1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3 * Copyright (c) 2016, Linaro Limited
4 */
5
6 #include <string.h>
7 #include <tee/uuid.h>
8 #include <util.h>
9
tee_uuid_to_octets(uint8_t * d,const TEE_UUID * s)10 void tee_uuid_to_octets(uint8_t *d, const TEE_UUID *s)
11 {
12 d[0] = s->timeLow >> 24;
13 d[1] = s->timeLow >> 16;
14 d[2] = s->timeLow >> 8;
15 d[3] = s->timeLow;
16 d[4] = s->timeMid >> 8;
17 d[5] = s->timeMid;
18 d[6] = s->timeHiAndVersion >> 8;
19 d[7] = s->timeHiAndVersion;
20 memcpy(d + 8, s->clockSeqAndNode, sizeof(s->clockSeqAndNode));
21 }
22
tee_uuid_from_octets(TEE_UUID * d,const uint8_t * s)23 void tee_uuid_from_octets(TEE_UUID *d, const uint8_t *s)
24 {
25 d->timeLow = SHIFT_U32(s[0], 24) | SHIFT_U32(s[1], 16) |
26 SHIFT_U32(s[2], 8) | s[3];
27 d->timeMid = SHIFT_U32(s[4], 8) | s[5];
28 d->timeHiAndVersion = SHIFT_U32(s[6], 8) | s[7];
29 memcpy(d->clockSeqAndNode, s + 8, sizeof(d->clockSeqAndNode));
30 }
31