blob: e320808dd3b8e44bf0cec4176a45201e09ae804e (
plain) (
blame)
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
|
#include "rw.h"
TRwSignature* RwSignatureNew(void) {
TRwSignature* sig = NULL;
sig = malloc(sizeof(TRwSignature));
if (!sig)
return NULL;
sig->S = NULL;
return sig;
}
void RwSignatureFree(TRwSignature* sig) {
if (sig) {
if (sig->S)
BN_free(sig->S);
free(sig);
}
}
int RwNoPaddingSign(int flen, const unsigned char* from, unsigned char* to, TRwKey* rw) {
int i = 0, r = 0, num = -1;
TRwSignature* sig = NULL;
if (!rw || !rw->N || !rw->Meth || !rw->Meth->RwSign || !from || !to)
goto err;
if ((sig = rw->Meth->RwSign(from, flen, rw)) == NULL)
goto err;
num = BN_num_bytes(rw->N);
r = BN_bn2bin(sig->S, to);
if (r < 0)
goto err;
/* put zeroes to the rest of the 'to' buffer */
for (i = r; i < num; i++) {
to[i] = 0x00;
}
err:
if (sig != NULL) {
RwSignatureFree(sig);
}
return r;
}
|