Update copyright headers for dual licensing.
[gd/nettle] / rsa-compat.h
1 /* rsa-compat.h
2
3    The RSA publickey algorithm, RSAREF compatible interface.
4
5    Copyright (C) 2001 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 #ifndef NETTLE_RSA_COMPAT_H_INCLUDED
35 #define NETTLE_RSA_COMPAT_H_INCLUDED
36
37 #include "rsa.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 /* Name mangling */
44 #define R_SignInit nettle_R_SignInit
45 #define R_SignUpdate nettle_R_SignUpdate
46 #define R_SignFinal nettle_R_SignFinal
47 #define R_VerifyInit nettle_R_VerifyInit
48 #define R_VerifyUpdate nettle_R_VerifyUpdate
49 #define R_VerifyFinal nettle_R_VerifyFinal
50
51 /* 256 octets or 2048 bits */
52 #define MAX_RSA_MODULUS_LEN 256
53
54 typedef struct
55 {
56   unsigned bits;
57   uint8_t modulus[MAX_RSA_MODULUS_LEN];
58   uint8_t exponent[MAX_RSA_MODULUS_LEN];
59 } R_RSA_PUBLIC_KEY;
60
61 typedef struct
62 {
63   unsigned bits;
64   uint8_t modulus[MAX_RSA_MODULUS_LEN];
65   uint8_t publicExponent[MAX_RSA_MODULUS_LEN];
66   uint8_t exponent[MAX_RSA_MODULUS_LEN];
67   uint8_t prime[2][MAX_RSA_MODULUS_LEN];
68   uint8_t primeExponent[2][MAX_RSA_MODULUS_LEN];
69   uint8_t coefficient[MAX_RSA_MODULUS_LEN];
70 } R_RSA_PRIVATE_KEY;
71
72 /* Only MD5 is supported for now */
73 typedef struct
74 {
75   struct md5_ctx hash;
76 } R_SIGNATURE_CTX;
77
78 /* Digest algorithms */
79 /* DA_MD2 not implemented */
80 enum { DA_MD5 = 1 };
81
82 /* Return values */
83 enum {
84   RE_SUCCESS = 0,
85   RE_CONTENT_ENCODING,     /* encryptedContent has RFC 1421 encoding error */
86   RE_DATA,                 /* other party's private value out of range */
87   RE_DIGEST_ALGORITHM,     /* message-digest algorithm is invalid */
88   RE_ENCODING,             /* encoded block has RFC 1421 encoding error */
89   RE_ENCRYPTION_ALGORITHM, /* encryption algorithm is invalid */
90   RE_KEY,                  /* recovered data encryption key cannot decrypt */
91   RE_KEY_ENCODING,         /* encrypted key has RFC 1421 encoding error */
92   RE_LEN,                  /* signatureLen out of range */
93   RE_MODULUS_LEN,          /* modulus length invalid */
94   RE_NEED_RANDOM,          /* random structure is not seeded */
95   RE_PRIVATE_KEY,          /* private key cannot encrypt message digest, */
96   RE_PUBLIC_KEY,           /* publicKey cannot decrypt signature */
97   RE_SIGNATURE,            /* signature is incorrect */
98   RE_SIGNATURE_ENCODING,   /* encodedSignature has RFC 1421 encoding error */
99 };
100
101 int
102 R_SignInit(R_SIGNATURE_CTX *ctx,
103            int digestAlgorithm);
104
105 int
106 R_SignUpdate(R_SIGNATURE_CTX *ctx,
107              const uint8_t *data,
108              /* Length is an unsigned char according to rsaref.txt,
109               * but that must be a typo. */
110              unsigned length);
111
112 int
113 R_SignFinal(R_SIGNATURE_CTX *ctx,
114             uint8_t *signature,
115             unsigned *length,
116             R_RSA_PRIVATE_KEY *key);
117
118 int
119 R_VerifyInit(R_SIGNATURE_CTX *ctx,
120              int digestAlgorithm);
121
122 int
123 R_VerifyUpdate(R_SIGNATURE_CTX *ctx,
124                const uint8_t *data,
125                /* Length is an unsigned char according to rsaref.txt,
126                 * but that must be a typo. */
127                unsigned length);
128
129 int
130 R_VerifyFinal(R_SIGNATURE_CTX *ctx,
131               uint8_t *signature,
132               unsigned length,
133               R_RSA_PUBLIC_KEY *key);
134
135 #ifdef __cplusplus
136 }
137 #endif
138
139 #endif /* NETTLE_RSA_COMPAT_H_INCLUDED */