-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
89 lines (77 loc) · 1.69 KB
/
main.c
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
/*
* Copyright (c) 2018 Amol Surati
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <arpa/inet.h>
#include <bn.h>
#include <rndm.h>
#include <ec.h>
#include <tls.h>
#include <sha2.h>
#include <hmac.h>
#include <hkdf.h>
#include <chacha.h>
#include <poly1305.h>
#include <aead.h>
// 3y^2=x^3 + 5x^2 + x mod 65537
// (3,5) on the curve.
// y^2=x^3 + 5x^2 + x mod eaad
// (4,0x94) on the curve
struct bn *bn_rand(const struct bn *m)
{
int nbits, nbytes;
uint8_t *bytes;
struct bn *t;
nbits = bn_msb(m) + 1;
nbytes = (nbits + 7) >> 3;
bytes = malloc(nbytes);
assert(bytes);
/* TODO more efficient way? */
for (;;) {
rndm_fill(bytes, nbits);
t = bn_new_from_bytes_be(bytes, nbytes);
/* TODO check for zero. */
if (bn_cmp_abs(t, m) < 0)
break;
bn_free(t);
}
return t;
}
const uint8_t tag[] = {
0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a
,0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55
,0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b
,0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
};
const uint8_t pub[] = {
0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07
,0x3a
,0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,0xf7
,0x07,0x51,0x1a
};
int main()
{
struct edc *edc;
bn_init();
edc = edc_new_verify(pub);
edc_verify(edc, tag, 64);
edc_free(edc);
bn_fini();
return 0;
}
#if 0
int main()
{
struct tls_ctx *ctx;
bn_init();
ctx = tls_ctx_new();
tls_client_machine(ctx, "127.0.0.1", 8443);
bn_fini();
return 0;
}
#endif