1 /* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 * SPDX-License-Identifier: Apache-2.0"
3 *
4 * Written by Nir Drucker, Shay Gueron and Dusan Kostic,
5 * AWS Cryptographic Algorithms Group.
6 */
7
8 #pragma once
9
10 #include <stddef.h>
11 #include <stdint.h>
12
13 #include "bike_defs.h"
14 #include "error.h"
15
16 typedef struct uint128_s {
17 union {
18 uint8_t bytes[16]; // NOLINT
19 uint32_t dw[4]; // NOLINT
20 uint64_t qw[2]; // NOLINT
21 } u;
22 } uint128_t;
23
24 // Make sure no compiler optimizations.
25 #pragma pack(push, 1)
26
27 typedef struct seed_s {
28 uint8_t raw[SEED_BYTES];
29 } seed_t;
30
31 typedef struct seeds_s {
32 seed_t seed[NUM_OF_SEEDS];
33 } seeds_t;
sha_dgst_cleanup(IN OUT sha_dgst_t * o)34
35 typedef struct r_s {
36 uint8_t raw[R_BYTES];
37 } r_t;
38
sha(OUT sha_dgst_t * hash_out,IN const uint32_t byte_len,IN const uint8_t * msg)39 typedef struct m_s {
40 uint8_t raw[M_BYTES];
41 } m_t;
42
43 typedef struct e_s {
44 r_t val[N0];
sha_mb(OUT sha_dgst_t * hash_out,IN const uint8_t * msg,IN const uint32_t byte_len,IN const uint32_t num)45 } e_t;
46
47 #define E0_RAW(e) ((e)->val[0].raw)
48 #define E1_RAW(e) ((e)->val[1].raw)
49
50 typedef struct ct_s {
51 r_t c0;
52 m_t c1;
53 } ct_t;
54
55 typedef r_t pk_t;
56
57 typedef struct ss_st {
58 uint8_t raw[SS_BYTES];
59 } ss_t;
60
61 typedef uint32_t idx_t;
62
63 typedef struct compressed_idx_d_s {
64 idx_t val[D];
65 } compressed_idx_d_t;
66
67 typedef compressed_idx_d_t compressed_idx_d_ar_t[N0];
68
69 // The secret key holds both representations, to avoid
70 // the compression in Decaps.
71 typedef struct sk_s {
72 compressed_idx_d_ar_t wlist;
73 r_t bin[N0];
74 pk_t pk;
75 m_t sigma;
76 } sk_t;
77
78 typedef ALIGN(sizeof(idx_t)) sk_t aligned_sk_t;
79
80 // Pad r to the next Block
81 typedef struct pad_r_s {
82 r_t val;
83 uint8_t pad[R_PADDED_BYTES - sizeof(r_t)];
84 } ALIGN(ALIGN_BYTES) pad_r_t;
85
86 // Double padded r, required for multiplication and squaring
87 typedef struct dbl_pad_r_s {
88 uint8_t raw[2 * R_PADDED_BYTES];
89 } ALIGN(ALIGN_BYTES) dbl_pad_r_t;
90
91 typedef struct pad_e_s {
92 pad_r_t val[N0];
93 } ALIGN(ALIGN_BYTES) pad_e_t;
94
95 #define PE0_RAW(e) ((e)->val[0].val.raw)
96 #define PE1_RAW(e) ((e)->val[1].val.raw)
97
98 typedef struct func_k_s {
99 m_t m;
100 r_t c0;
101 m_t c1;
102 } func_k_t;
103
104 // For a faster rotate we triplicate the syndrome (into 3 copies)
105 typedef struct syndrome_s {
106 uint64_t qw[3 * R_QWORDS];
107 } ALIGN(ALIGN_BYTES) syndrome_t;
108
109 typedef struct upc_slice_s {
110 union {
111 pad_r_t r;
112 uint64_t qw[sizeof(pad_r_t) / sizeof(uint64_t)];
113 } ALIGN(ALIGN_BYTES) u;
114 } ALIGN(ALIGN_BYTES) upc_slice_t;
115
116 typedef struct upc_s {
117 upc_slice_t slice[SLICES];
118 } upc_t;
119
120 #pragma pack(pop)
121