3 PKCS stuff for rsa-sha1.
5 Copyright (C) 2001, 2003 Niels Möller
7 This file is part of GNU Nettle.
9 GNU Nettle is free software: you can redistribute it and/or
10 modify it under the terms of either:
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.
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.
22 or both in parallel, as here.
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.
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/.
51 * id-sha1 OBJECT IDENTIFIER ::=
52 * {iso(1) identified-organization(3) oiw(14) secsig(3)
55 * The default hash function is SHA-1:
56 * sha1Identifier ::= AlgorithmIdentifier {id-sha1, NULL}
62 /* 15 octets prefix, 20 octets hash, total 35 */
63 0x30, 33, /* SEQUENCE */
64 0x30, 9, /* SEQUENCE */
65 0x06, 5, /* OBJECT IDENTIFIER */
66 0x2b, 0x0e, 0x03, 0x02, 0x1a,
68 0x04, 20 /* OCTET STRING */
69 /* Here comes the raw hash value */
73 pkcs1_rsa_sha1_encode(mpz_t m, size_t key_size, struct sha1_ctx *hash)
76 TMP_GMP_DECL(em, uint8_t);
78 TMP_GMP_ALLOC(em, key_size);
80 p = _pkcs1_signature_prefix(key_size, em,
86 sha1_digest(hash, SHA1_DIGEST_SIZE, p);
87 nettle_mpz_set_str_256_u(m, key_size, em);
99 pkcs1_rsa_sha1_encode_digest(mpz_t m, size_t key_size, const uint8_t *digest)
102 TMP_GMP_DECL(em, uint8_t);
104 TMP_GMP_ALLOC(em, key_size);
106 p = _pkcs1_signature_prefix(key_size, em,
112 memcpy(p, digest, SHA1_DIGEST_SIZE);
113 nettle_mpz_set_str_256_u(m, key_size, em);