-
Notifications
You must be signed in to change notification settings - Fork 1
/
crypto_sign.c.in
48 lines (38 loc) · 1.17 KB
/
crypto_sign.c.in
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
/*
* SPDX-License-Identifier: MIT
*/
#ifdef SUPERCOP
#include "crypto_sign.h"
#else
#include "api.h"
#endif
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "faest_@PARAM_L@.h"
#include <string.h>
int crypto_sign_keypair(unsigned char* pk, unsigned char* sk) {
return faest_@PARAM_L@_keygen(pk, sk);
}
int crypto_sign(unsigned char* sm, unsigned long long* smlen, const unsigned char* m,
unsigned long long mlen, const unsigned char* sk) {
*smlen = mlen + FAEST_@PARAM@_SIGNATURE_SIZE;
memmove(sm, m, mlen);
size_t signature_len = FAEST_@PARAM@_SIGNATURE_SIZE;
return faest_@PARAM_L@_sign(sk, sm, mlen, sm + mlen, &signature_len);
}
int crypto_sign_open(unsigned char* m, unsigned long long* mlen, const unsigned char* sm,
unsigned long long smlen, const unsigned char* pk) {
if (smlen < FAEST_@PARAM@_SIGNATURE_SIZE) {
// signature too short
return -1;
}
unsigned long long m_length = smlen - FAEST_@PARAM@_SIGNATURE_SIZE;
if (faest_@PARAM_L@_verify(pk, sm, m_length, sm + m_length, FAEST_@PARAM@_SIGNATURE_SIZE)) {
return -1;
}
*mlen = m_length;
memmove(m, sm, m_length);
return 0;
}
// vim: ft=c