Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /* pkcs1.c  | 
2  |  |  | 
3  |  |    PKCS1 embedding.  | 
4  |  |  | 
5  |  |    Copyright (C) 2003 Niels Möller  | 
6  |  |  | 
7  |  |    This file is part of GNU Nettle.  | 
8  |  |  | 
9  |  |    GNU Nettle is free software: you can redistribute it and/or  | 
10  |  |    modify it under the terms of either:  | 
11  |  |  | 
12  |  |      * the GNU Lesser General Public License as published by the Free  | 
13  |  |        Software Foundation; either version 3 of the License, or (at your  | 
14  |  |        option) any later version.  | 
15  |  |  | 
16  |  |    or  | 
17  |  |  | 
18  |  |      * the GNU General Public License as published by the Free  | 
19  |  |        Software Foundation; either version 2 of the License, or (at your  | 
20  |  |        option) any later version.  | 
21  |  |  | 
22  |  |    or both in parallel, as here.  | 
23  |  |  | 
24  |  |    GNU Nettle is distributed in the hope that it will be useful,  | 
25  |  |    but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
26  |  |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  | 
27  |  |    General Public License for more details.  | 
28  |  |  | 
29  |  |    You should have received copies of the GNU General Public License and  | 
30  |  |    the GNU Lesser General Public License along with this program.  If  | 
31  |  |    not, see http://www.gnu.org/licenses/.  | 
32  |  | */  | 
33  |  |  | 
34  |  | #if HAVE_CONFIG_H  | 
35  |  | # include "config.h"  | 
36  |  | #endif  | 
37  |  |  | 
38  |  | #include <assert.h>  | 
39  |  | #include <string.h>  | 
40  |  |  | 
41  |  | #include "pkcs1.h"  | 
42  |  | #include "hogweed-internal.h"  | 
43  |  |  | 
44  |  | /* Formats the PKCS#1 padding, of the form  | 
45  |  |  *  | 
46  |  |  *   0x00 0x01 0xff ... 0xff 0x00 id ...digest...  | 
47  |  |  *  | 
48  |  |  * where the 0xff ... 0xff part consists of at least 8 octets. The   | 
49  |  |  * total size equals the octet size of n.  | 
50  |  |  */  | 
51  |  | uint8_t *  | 
52  |  | _pkcs1_signature_prefix(unsigned key_size,  | 
53  |  |       uint8_t *buffer,  | 
54  |  |       unsigned id_size,  | 
55  |  |       const uint8_t *id,  | 
56  |  |       unsigned digest_size)  | 
57  | 0  | { | 
58  | 0  |   unsigned j;  | 
59  |  |     | 
60  | 0  |   if (key_size < 11 + id_size + digest_size)  | 
61  | 0  |     return NULL;  | 
62  |  |  | 
63  | 0  |   j = key_size - digest_size - id_size;  | 
64  |  | 
  | 
65  | 0  |   memcpy (buffer + j, id, id_size);  | 
66  | 0  |   buffer[0] = 0;  | 
67  | 0  |   buffer[1] = 1;  | 
68  | 0  |   buffer[j-1] = 0;  | 
69  |  | 
  | 
70  | 0  |   assert(j >= 11);  | 
71  | 0  |   memset(buffer + 2, 0xff, j - 3);  | 
72  |  | 
  | 
73  | 0  |   return buffer + j + id_size;  | 
74  | 0  | }  |