aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/aws/s2n/pq-crypto/bike_r1/cleanup.h
blob: 6bacfaa45ab7f257d39af0e7e0664e80d37bd5f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0"
 *
 * Written by Nir Drucker and Shay Gueron
 * AWS Cryptographic Algorithms Group.
 * (ndrucker@amazon.com, gueron@amazon.com)
 */

#pragma once
#include "types.h"
#include "utils/s2n_safety.h"

_INLINE_ void
secure_clean(OUT uint8_t *p, IN const uint32_t len)
{
#ifdef _WIN32
  SecureZeroMemory(p, len);
#else
  typedef void *(*memset_t)(void *, int, size_t);
  static volatile memset_t memset_func = memset;
  memset_func(p, 0, len);
#endif
}

_INLINE_ void
r_cleanup(IN OUT r_t *o)
{
  secure_clean((uint8_t *)o, sizeof(*o));
}

_INLINE_ void
e_cleanup(IN OUT e_t *o)
{
  secure_clean((uint8_t *)o, sizeof(*o));
}

_INLINE_ void
padded_r_cleanup(IN OUT padded_r_t *o)
{
  secure_clean((uint8_t *)o, sizeof(*o));
}

_INLINE_ void
padded_e_cleanup(IN OUT padded_e_t *o)
{
  secure_clean((uint8_t *)o, sizeof(*o));
}

_INLINE_ void
split_e_cleanup(IN OUT split_e_t *o)
{
  secure_clean((uint8_t *)o, sizeof(*o));
}

_INLINE_ void
sk_cleanup(IN OUT sk_t *o)
{
  secure_clean((uint8_t *)o, sizeof(*o));
}

_INLINE_ void
pad_sk_cleanup(IN OUT pad_sk_t *o)
{
  secure_clean((uint8_t *)o[0], sizeof(*o));
}

_INLINE_ void
pad_ct_cleanup(IN OUT pad_ct_t *o)
{
  secure_clean((uint8_t *)o[0], sizeof(*o));
}

_INLINE_ void
dbl_pad_ct_cleanup(IN OUT dbl_pad_ct_t *o)
{
  secure_clean((uint8_t *)o[0], sizeof(*o));
}

_INLINE_ void
seed_cleanup(IN OUT seed_t *o)
{
  secure_clean((uint8_t *)o, sizeof(*o));
}

_INLINE_ void
syndrome_cleanup(IN OUT syndrome_t *o)
{
  secure_clean((uint8_t *)o, sizeof(*o));
}

_INLINE_ void
dbl_pad_syndrome_cleanup(IN OUT dbl_pad_syndrome_t *o)
{
  secure_clean((uint8_t *)o[0], sizeof(*o));
}

_INLINE_ void
compressed_idx_t_cleanup(IN OUT compressed_idx_t_t *o)
{
  secure_clean((uint8_t *)o, sizeof(*o));
}

_INLINE_ void
compressed_idx_dv_ar_cleanup(IN OUT compressed_idx_dv_ar_t *o)
{
  for(int i = 0; i < N0; i++)
  {
    secure_clean((uint8_t *)&(*o)[i], sizeof((*o)[0]));
  }
}

_INLINE_ void
generic_param_n_cleanup(IN OUT generic_param_n_t *o)
{
  secure_clean((uint8_t *)o, sizeof(*o));
}

_INLINE_ void
seeds_cleanup(IN OUT seeds_t *o)
{
  for(int i = 0; i < NUM_OF_SEEDS; i++)
  {
    seed_cleanup(&(o->seed[i]));
  }
}

_INLINE_ void
upc_cleanup(IN OUT upc_t *o)
{
  secure_clean((uint8_t *)o, sizeof(*o));
}