/src/nettle/gostdsa-sign.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /* gostdsa-sign.c  | 
2  |  |  | 
3  |  |    Copyright (C) 2015 Dmitry Eremin-Solenikov  | 
4  |  |    Copyright (C) 2013 Niels Möller  | 
5  |  |  | 
6  |  |    This file is part of GNU Nettle.  | 
7  |  |  | 
8  |  |    GNU Nettle is free software: you can redistribute it and/or  | 
9  |  |    modify it under the terms of either:  | 
10  |  |  | 
11  |  |      * the GNU Lesser General Public License as published by the Free  | 
12  |  |        Software Foundation; either version 3 of the License, or (at your  | 
13  |  |        option) any later version.  | 
14  |  |  | 
15  |  |    or  | 
16  |  |  | 
17  |  |      * the GNU General Public License as published by the Free  | 
18  |  |        Software Foundation; either version 2 of the License, or (at your  | 
19  |  |        option) any later version.  | 
20  |  |  | 
21  |  |    or both in parallel, as here.  | 
22  |  |  | 
23  |  |    GNU Nettle is distributed in the hope that it will be useful,  | 
24  |  |    but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
25  |  |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  | 
26  |  |    General Public License for more details.  | 
27  |  |  | 
28  |  |    You should have received copies of the GNU General Public License and  | 
29  |  |    the GNU Lesser General Public License along with this program.  If  | 
30  |  |    not, see http://www.gnu.org/licenses/.  | 
31  |  | */  | 
32  |  |  | 
33  |  | #if HAVE_CONFIG_H  | 
34  |  | # include "config.h"  | 
35  |  | #endif  | 
36  |  |  | 
37  |  | #include <assert.h>  | 
38  |  | #include <stdlib.h>  | 
39  |  |  | 
40  |  | #include "gostdsa.h"  | 
41  |  | #include "ecc-internal.h"  | 
42  |  | #include "nettle-internal.h"  | 
43  |  |  | 
44  |  | void  | 
45  |  | gostdsa_sign (const struct ecc_scalar *key,  | 
46  |  |       void *random_ctx, nettle_random_func *random,  | 
47  |  |       size_t digest_length,  | 
48  |  |       const uint8_t *digest,  | 
49  |  |       struct dsa_signature *signature)  | 
50  | 0  | { | 
51  |  |   /* At most 936 bytes. */  | 
52  | 0  |   TMP_DECL(k, mp_limb_t, ECC_MAX_SIZE + ECC_GOSTDSA_SIGN_ITCH (ECC_MAX_SIZE));  | 
53  | 0  |   mp_limb_t size = key->ecc->p.size;  | 
54  | 0  |   mp_limb_t *rp = mpz_limbs_write (signature->r, size);  | 
55  | 0  |   mp_limb_t *sp = mpz_limbs_write (signature->s, size);  | 
56  |  | 
  | 
57  | 0  |   TMP_ALLOC (k, size + ECC_GOSTDSA_SIGN_ITCH (size));  | 
58  |  |  | 
59  |  |   /* Timing reveals the number of rounds through this loop, but the  | 
60  |  |      timing is still independent of the secret k finally used. */  | 
61  | 0  |   do  | 
62  | 0  |     { | 
63  | 0  |       do  | 
64  | 0  |         { | 
65  | 0  |           ecc_mod_random (&key->ecc->q, k, random_ctx, random, k + size);  | 
66  | 0  |   }  | 
67  | 0  |       while (mpn_zero_p(k, size));  | 
68  | 0  |       ecc_gostdsa_sign (key->ecc, key->p, k, digest_length, digest,  | 
69  | 0  |        rp, sp, k + size);  | 
70  | 0  |       mpz_limbs_finish (signature->r, size);  | 
71  | 0  |       mpz_limbs_finish (signature->s, size);  | 
72  | 0  |     }  | 
73  | 0  |   while (mpz_sgn (signature->r) == 0 || mpz_sgn (signature->s) == 0);  | 
74  | 0  | }  |