forked from kj3moraes/further-testing-xmss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nist.c
164 lines (142 loc) · 3.6 KB
/
nist.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*=============================================================================
* Copyright (c) 2022 by SandboxAQ Inc
* Author: Duc Tri Nguyen
* SPDX-License-Identifier: MIT
=============================================================================*/
#include <oqs/common.h>
#include <stdio.h>
#include "api.h"
#include "params.h"
#include "nist_params.h"
#include "xmss.h"
#include "thread_wrapper.h"
int XMSS_search_cpu (void) __attribute__((constructor));
int crypto_sign_keypair(unsigned char *pk, unsigned char *sk)
{
xmss_params params;
uint32_t oid;
int ret = 0;
ret |= XMSS_STR_TO_OID(&oid, XMSS_OID);
if (ret)
{
#if DEBUG
printf("Did not recognize %s!\n", XMSS_OID);
#endif
return OQS_ERROR;
}
ret |= XMSS_PARSE_OID(¶ms, oid);
if (ret)
{
#if DEBUG
printf("Could not parse OID for %s!\n", XMSS_OID);
#endif
return OQS_ERROR;
}
#if DEBUG
printf("sklen, pklen, siglen = %llu, %u, %u\n", params.sk_bytes, params.pk_bytes, params.sig_bytes);
#endif
ret |= XMSS_KEYPAIR(pk, sk, oid);
if (ret)
{
#if DEBUG
printf("Error generating keypair %d\n", ret);
#endif
return OQS_ERROR;
}
return OQS_SUCCESS;
}
int crypto_sign(unsigned char *sm, unsigned long long *smlen,
const unsigned char *m, unsigned long long mlen, unsigned char *sk)
{
int ret = XMSS_SIGN(sk, sm, smlen, m, mlen);
if (ret)
{
#if DEBUG
printf("Error generating signature %d\n", ret);
#endif
return OQS_ERROR;
}
return OQS_SUCCESS;
}
int crypto_sign_open(unsigned char *m, unsigned long long *mlen,
const unsigned char *sm, unsigned long long smlen, const unsigned char *pk)
{
if (XMSS_SIGN_OPEN(m, mlen, sm, smlen, pk))
{
#if DEBUG
printf("Error verifying signature %d\n", ret);
#endif
return OQS_ERROR;
}
return OQS_SUCCESS;
}
int crypto_remaining_signatures(unsigned long long *remain, const unsigned char *sk)
{
if (XMSS_REMAINING_SIG(remain, sk))
{
#if DEBUG
printf("Error counting remaining signatures\n");
#endif
return OQS_ERROR;
}
return OQS_SUCCESS;
}
int crypto_sign_keypair_mp(unsigned char *pk, unsigned char *sk)
{
xmss_params params;
uint32_t oid;
int ret = 0;
ret |= XMSS_STR_TO_OID(&oid, XMSS_OID);
if (ret)
{
#if DEBUG
printf("Did not recognize %s!\n", XMSS_OID);
#endif
return OQS_ERROR;
}
ret |= XMSS_PARSE_OID(¶ms, oid);
if (ret)
{
#if DEBUG
printf("Could not parse OID for %s!\n", XMSS_OID);
#endif
return OQS_ERROR;
}
#if DEBUG
printf("sklen, pklen, siglen = %llu, %u, %u\n", params.sk_bytes, params.pk_bytes, params.sig_bytes);
#endif
ret |= XMSS_KEYPAIR_MP(pk, sk, oid);
if (ret)
{
#if DEBUG
printf("Error generating keypair %d\n", ret);
#endif
return OQS_ERROR;
}
return OQS_SUCCESS;
}
int crypto_sign_mp(unsigned char *sm, unsigned long long *smlen,
const unsigned char *m, unsigned long long mlen, unsigned char *sk)
{
int ret = XMSS_SIGN_MP(sk, sm, smlen, m, mlen);
if (ret)
{
#if DEBUG
printf("Error generating signature %d\n", ret);
#endif
return OQS_ERROR;
}
return OQS_SUCCESS;
}
int crypto_sign_open_mp(unsigned char *m, unsigned long long *mlen,
const unsigned char *sm, unsigned long long smlen, const unsigned char *pk)
{
if (XMSS_SIGN_OPEN_MP(m, mlen, sm, smlen, pk))
{
#if DEBUG
printf("Error verifying signature %d\n", ret);
#endif
return OQS_ERROR;
}
return OQS_SUCCESS;
}