-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLatticeCrypto_priv.h
125 lines (87 loc) · 4.39 KB
/
LatticeCrypto_priv.h
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
/****************************************************************************************
* LatticeCrypto: an efficient post-quantum Ring-Learning With Errors cryptography library
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*
* Abstract: internal header file
*
*****************************************************************************************/
#ifndef __LatticeCrypto_priv_H__
#define __LatticeCrypto_priv_H__
// For C++
#ifdef __cplusplus
extern "C" {
#endif
#include "LatticeCrypto.h"
// Basic constants
#define PARAMETER_N 1024
#define PARAMETER_Q 12289
#define SEED_BYTES 256/8
#define ERROR_SEED_BYTES 256/8
#define NONCE_SEED_BYTES 256/8
#define PARAMETER_Q4 3073
#define PARAMETER_3Q4 9217
#define PARAMETER_5Q4 15362
#define PARAMETER_7Q4 21506
#define PARAMETER_Q2 6145
#define PARAMETER_3Q2 18434
// Macro definitions
#define NBITS_TO_NWORDS(nbits) (((nbits)+(sizeof(digit_t)*8)-1)/(sizeof(digit_t)*8)) // Conversion macro from number of bits to number of computer words
#define NBYTES_TO_NWORDS(nbytes) (((nbytes)+sizeof(digit_t)-1)/sizeof(digit_t)) // Conversion macro from number of bytes to number of computer words
// Macro to avoid compiler warnings when detecting unreferenced parameters
#define UNREFERENCED_PARAMETER(PAR) (PAR)
/******************** Function prototypes *******************/
/******************* Polynomial functions *******************/
// Forward NTT
void NTT_CT_std2rev_12289(int32_t* a, const int32_t* psi_rev, unsigned int N);
void NTT_CT_std2rev_12289_asm(int32_t* a, const int32_t* psi_rev, unsigned int N);
// Inverse NTT
void INTT_GS_rev2std_12289(int32_t* a, const int32_t* omegainv_rev, const int32_t omegainv1N_rev, const int32_t Ninv, unsigned int N);
void INTT_GS_rev2std_12289_asm(int32_t* a, const int32_t* omegainv_rev, const int32_t omegainv1N_rev, const int32_t Ninv, unsigned int N);
// Reduction modulo q
int32_t reduce12289(int64_t a);
// Two merged reductions modulo q
int32_t reduce12289_2x(int64_t a);
// Two consecutive reductions modulo q
void two_reduce12289(int32_t* a, unsigned int N);
void two_reduce12289_asm(int32_t* a, unsigned int N);
// Correction modulo q
void correction(int32_t* a, int32_t p, unsigned int N);
// Component-wise multiplication
void pmul(int32_t* a, int32_t* b, int32_t* c, unsigned int N);
void pmul_asm(int32_t* a, int32_t* b, int32_t* c, unsigned int N);
// Component-wise multiplication and addition
void pmuladd(int32_t* a, int32_t* b, int32_t* c, int32_t* d, unsigned int N);
void pmuladd_asm(int32_t* a, int32_t* b, int32_t* c, int32_t* d, unsigned int N);
// Component-wise multiplication with scalar
void smul(int32_t* a, int32_t scalar, unsigned int N);
/******************* Key exchange functions *******************/
// Alice's message encoding
void encode_A(const uint32_t* pk, const unsigned char* seed, unsigned char* m);
// Alice's message decoding
void decode_A(const unsigned char* m, uint32_t *pk, unsigned char* seed);
// Bob's message encoding
void encode_B(const uint32_t* pk, const uint32_t* rvec, unsigned char* m);
// Bob's message decoding
void decode_B(unsigned char* m, uint32_t* pk, uint32_t* rvec);
// Partial message encoding/decoding (assembly optimized)
void encode_asm(const uint32_t* pk, unsigned char* m);
void decode_asm(const unsigned char* m, uint32_t *pk);
// Reconciliation helper
CRYPTO_STATUS HelpRec(const uint32_t* x, uint32_t* rvec, const unsigned char* seed, unsigned int nonce, StreamOutput StreamOutputFunction);
// Partial reconciliation helper (assembly optimized)
void helprec_asm(const uint32_t* x, uint32_t* rvec, unsigned char* random_bits);
// Reconciliation
void Rec(const uint32_t *x, const uint32_t* rvec, unsigned char *key);
void rec_asm(const uint32_t *x, const uint32_t* rvec, unsigned char *key);
// Error sampling
CRYPTO_STATUS get_error(int32_t* e, unsigned char* seed, unsigned int nonce, StreamOutput StreamOutputFunction);
// Partial error sampling (assembly optimized)
void error_sampling_asm(unsigned char* stream, int32_t* e);
// Generation of parameter a
CRYPTO_STATUS generate_a(uint32_t* a, const unsigned char* seed, ExtendableOutput ExtendableOutputFunction);
#ifdef __cplusplus
}
#endif
#endif