-
Notifications
You must be signed in to change notification settings - Fork 22
/
bearssl_ec_h.lua
122 lines (122 loc) · 4.44 KB
/
bearssl_ec_h.lua
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
local ffi = require'ffi'
ffi.cdef[[
enum {
BR_EC_sect163k1 = 1,
BR_EC_sect163r1 = 2,
BR_EC_sect163r2 = 3,
BR_EC_sect193r1 = 4,
BR_EC_sect193r2 = 5,
BR_EC_sect233k1 = 6,
BR_EC_sect233r1 = 7,
BR_EC_sect239k1 = 8,
BR_EC_sect283k1 = 9,
BR_EC_sect283r1 = 10,
BR_EC_sect409k1 = 11,
BR_EC_sect409r1 = 12,
BR_EC_sect571k1 = 13,
BR_EC_sect571r1 = 14,
BR_EC_secp160k1 = 15,
BR_EC_secp160r1 = 16,
BR_EC_secp160r2 = 17,
BR_EC_secp192k1 = 18,
BR_EC_secp192r1 = 19,
BR_EC_secp224k1 = 20,
BR_EC_secp224r1 = 21,
BR_EC_secp256k1 = 22,
BR_EC_secp256r1 = 23,
BR_EC_secp384r1 = 24,
BR_EC_secp521r1 = 25,
BR_EC_brainpoolP256r1 = 26,
BR_EC_brainpoolP384r1 = 27,
BR_EC_brainpoolP512r1 = 28,
BR_EC_curve25519 = 29,
BR_EC_curve448 = 30,
};
typedef struct {
int curve;
unsigned char *q;
size_t qlen;
} br_ec_public_key;
typedef struct {
int curve;
unsigned char *x;
size_t xlen;
} br_ec_private_key;
typedef struct {
uint32_t supported_curves;
const unsigned char *(*generator)(int curve, size_t *len);
const unsigned char *(*order)(int curve, size_t *len);
size_t (*xoff)(int curve, size_t *len);
uint32_t (*mul)(unsigned char *G, size_t Glen,
const unsigned char *x, size_t xlen, int curve);
size_t (*mulgen)(unsigned char *R,
const unsigned char *x, size_t xlen, int curve);
uint32_t (*muladd)(unsigned char *A, const unsigned char *B, size_t len,
const unsigned char *x, size_t xlen,
const unsigned char *y, size_t ylen, int curve);
} br_ec_impl;
extern const br_ec_impl br_ec_prime_i31;
extern const br_ec_impl br_ec_prime_i15;
extern const br_ec_impl br_ec_p256_m15;
extern const br_ec_impl br_ec_p256_m31;
extern const br_ec_impl br_ec_p256_m62;
const br_ec_impl *br_ec_p256_m62_get(void);
extern const br_ec_impl br_ec_p256_m64;
const br_ec_impl *br_ec_p256_m64_get(void);
extern const br_ec_impl br_ec_c25519_i15;
extern const br_ec_impl br_ec_c25519_i31;
extern const br_ec_impl br_ec_c25519_m15;
extern const br_ec_impl br_ec_c25519_m31;
extern const br_ec_impl br_ec_c25519_m62;
const br_ec_impl *br_ec_c25519_m62_get(void);
extern const br_ec_impl br_ec_c25519_m64;
const br_ec_impl *br_ec_c25519_m64_get(void);
extern const br_ec_impl br_ec_all_m15;
extern const br_ec_impl br_ec_all_m31;
const br_ec_impl *br_ec_get_default(void);
size_t br_ecdsa_raw_to_asn1(void *sig, size_t sig_len);
size_t br_ecdsa_asn1_to_raw(void *sig, size_t sig_len);
typedef size_t (*br_ecdsa_sign)(const br_ec_impl *impl,
const br_hash_class *hf, const void *hash_value,
const br_ec_private_key *sk, void *sig);
typedef uint32_t (*br_ecdsa_vrfy)(const br_ec_impl *impl,
const void *hash, size_t hash_len,
const br_ec_public_key *pk, const void *sig, size_t sig_len);
size_t br_ecdsa_i31_sign_asn1(const br_ec_impl *impl,
const br_hash_class *hf, const void *hash_value,
const br_ec_private_key *sk, void *sig);
size_t br_ecdsa_i31_sign_raw(const br_ec_impl *impl,
const br_hash_class *hf, const void *hash_value,
const br_ec_private_key *sk, void *sig);
uint32_t br_ecdsa_i31_vrfy_asn1(const br_ec_impl *impl,
const void *hash, size_t hash_len,
const br_ec_public_key *pk, const void *sig, size_t sig_len);
uint32_t br_ecdsa_i31_vrfy_raw(const br_ec_impl *impl,
const void *hash, size_t hash_len,
const br_ec_public_key *pk, const void *sig, size_t sig_len);
size_t br_ecdsa_i15_sign_asn1(const br_ec_impl *impl,
const br_hash_class *hf, const void *hash_value,
const br_ec_private_key *sk, void *sig);
size_t br_ecdsa_i15_sign_raw(const br_ec_impl *impl,
const br_hash_class *hf, const void *hash_value,
const br_ec_private_key *sk, void *sig);
uint32_t br_ecdsa_i15_vrfy_asn1(const br_ec_impl *impl,
const void *hash, size_t hash_len,
const br_ec_public_key *pk, const void *sig, size_t sig_len);
uint32_t br_ecdsa_i15_vrfy_raw(const br_ec_impl *impl,
const void *hash, size_t hash_len,
const br_ec_public_key *pk, const void *sig, size_t sig_len);
br_ecdsa_sign br_ecdsa_sign_asn1_get_default(void);
br_ecdsa_sign br_ecdsa_sign_raw_get_default(void);
br_ecdsa_vrfy br_ecdsa_vrfy_asn1_get_default(void);
br_ecdsa_vrfy br_ecdsa_vrfy_raw_get_default(void);
enum {
BR_EC_KBUF_PRIV_MAX_SIZE = 72,
BR_EC_KBUF_PUB_MAX_SIZE = 145,
};
size_t br_ec_keygen(const br_prng_class **rng_ctx,
const br_ec_impl *impl, br_ec_private_key *sk,
void *kbuf, int curve);
size_t br_ec_compute_pub(const br_ec_impl *impl, br_ec_public_key *pk,
void *kbuf, const br_ec_private_key *sk);
]]