1 /*############################################################################
2 # Copyright 2017 Intel Corporation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 ############################################################################*/
16 /// Tiny member SetSigRl implementation.
17 /*! \file */
18
19 #define EXPORT_EPID_APIS
20 #include <epid/member/api.h>
21
22 #include "epid/member/tiny/src/context.h"
23 #include "epid/member/tiny/stdlib/endian.h"
24 #include "epid/member/tiny/stdlib/tiny_stdlib.h"
25
EpidMemberSetSigRl(MemberCtx * ctx,SigRl const * sig_rl,size_t sig_rl_size)26 EpidStatus EPID_API EpidMemberSetSigRl(MemberCtx* ctx, SigRl const* sig_rl,
27 size_t sig_rl_size) {
28 uint32_t n2_in = 0;
29 size_t calculated_sig_rl_size = 0;
30 uint32_t i = 0;
31 if (!ctx || !sig_rl) {
32 return kEpidBadArgErr;
33 }
34
35 if (!ctx->is_provisioned) {
36 return kEpidOutOfSequenceError;
37 }
38
39 n2_in = be32toh(sig_rl->n2);
40
41 // sanity check SigRl size
42 if (n2_in > MAX_SIGRL_ENTRIES) {
43 return kEpidBadArgErr;
44 }
45 calculated_sig_rl_size = MIN_SIGRL_SIZE + n2_in * sizeof(sig_rl->bk[0]);
46 if (calculated_sig_rl_size != sig_rl_size) {
47 return kEpidBadArgErr;
48 }
49 // verify that gid given and gid in SigRl match
50 if (0 != memcmp(&ctx->pub_key.gid, &sig_rl->gid, sizeof(sig_rl->gid))) {
51 return kEpidBadArgErr;
52 }
53
54 // ensure version is not being reverted
55 if (ctx->sig_rl) {
56 uint32_t current_ver = be32toh(ctx->sig_rl->version);
57 uint32_t incoming_ver = be32toh(sig_rl->version);
58 if (current_ver >= incoming_ver) {
59 return kEpidBadArgErr;
60 }
61 }
62
63 #ifdef USE_SIGRL_BY_REFERENCE
64 ctx->sig_rl = (SigRl*)sig_rl;
65 (void)i;
66 #else
67 if (!ctx->sig_rl) {
68 ctx->sig_rl = (SigRl*)ctx->heap;
69 }
70 ctx->sig_rl->version = sig_rl->version;
71 ctx->sig_rl->n2 = sig_rl->n2;
72 memset(ctx->sig_rl->bk, 0, MAX_SIGRL_ENTRIES * sizeof(*ctx->sig_rl->bk));
73
74 for (i = 0; i < n2_in; i++) {
75 ctx->sig_rl->bk[i] = sig_rl->bk[i];
76 }
77 #endif
78 return kEpidNoErr;
79 }
80