[MBEDTLS] Use mbedtls as a lightweight schannel TLS/SSL back-end. This is an initial...
[reactos.git] / reactos / include / reactos / libs / gnutls / nettle / rsa-compat.h
1 /* rsa-compat.h
2 *
3 * The RSA publickey algorithm, RSAREF compatible interface.
4 */
5
6 /* nettle, low-level cryptographics library
7 *
8 * Copyright (C) 2001 Niels Möller
9 *
10 * The nettle library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or (at your
13 * option) any later version.
14 *
15 * The nettle library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the nettle library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 * MA 02111-1301, USA.
24 */
25
26 #ifndef NETTLE_RSA_COMPAT_H_INCLUDED
27 #define NETTLE_RSA_COMPAT_H_INCLUDED
28
29 #include "rsa.h"
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /* Name mangling */
36 #define R_SignInit nettle_R_SignInit
37 #define R_SignUpdate nettle_R_SignUpdate
38 #define R_SignFinal nettle_R_SignFinal
39 #define R_VerifyInit nettle_R_VerifyInit
40 #define R_VerifyUpdate nettle_R_VerifyUpdate
41 #define R_VerifyFinal nettle_R_VerifyFinal
42
43 /* 256 octets or 2048 bits */
44 #define MAX_RSA_MODULUS_LEN 256
45
46 typedef struct {
47 unsigned bits;
48 uint8_t modulus[MAX_RSA_MODULUS_LEN];
49 uint8_t exponent[MAX_RSA_MODULUS_LEN];
50 } R_RSA_PUBLIC_KEY;
51
52 typedef struct {
53 unsigned bits;
54 uint8_t modulus[MAX_RSA_MODULUS_LEN];
55 uint8_t publicExponent[MAX_RSA_MODULUS_LEN];
56 uint8_t exponent[MAX_RSA_MODULUS_LEN];
57 uint8_t prime[2][MAX_RSA_MODULUS_LEN];
58 uint8_t primeExponent[2][MAX_RSA_MODULUS_LEN];
59 uint8_t coefficient[MAX_RSA_MODULUS_LEN];
60 } R_RSA_PRIVATE_KEY;
61
62 /* Only MD5 is supported for now */
63 typedef struct {
64 struct md5_ctx hash;
65 } R_SIGNATURE_CTX;
66
67 /* Digest algorithms */
68 /* DA_MD2 not implemented */
69 enum { DA_MD5 = 1 };
70
71 /* Return values */
72 enum {
73 RE_SUCCESS = 0,
74 RE_CONTENT_ENCODING, /* encryptedContent has RFC 1421 encoding error */
75 RE_DATA, /* other party's private value out of range */
76 RE_DIGEST_ALGORITHM, /* message-digest algorithm is invalid */
77 RE_ENCODING, /* encoded block has RFC 1421 encoding error */
78 RE_ENCRYPTION_ALGORITHM, /* encryption algorithm is invalid */
79 RE_KEY, /* recovered data encryption key cannot decrypt */
80 RE_KEY_ENCODING, /* encrypted key has RFC 1421 encoding error */
81 RE_LEN, /* signatureLen out of range */
82 RE_MODULUS_LEN, /* modulus length invalid */
83 RE_NEED_RANDOM, /* random structure is not seeded */
84 RE_PRIVATE_KEY, /* private key cannot encrypt message digest, */
85 RE_PUBLIC_KEY, /* publicKey cannot decrypt signature */
86 RE_SIGNATURE, /* signature is incorrect */
87 RE_SIGNATURE_ENCODING, /* encodedSignature has RFC 1421 encoding error */
88 };
89
90 int
91 R_SignInit(R_SIGNATURE_CTX * ctx, int digestAlgorithm);
92
93 int
94 R_SignUpdate(R_SIGNATURE_CTX * ctx, const uint8_t * data,
95 /* Length is an unsigned char according to rsaref.txt,
96 * but that must be a typo. */
97 unsigned length);
98
99 int
100 R_SignFinal(R_SIGNATURE_CTX * ctx,
101 uint8_t * signature,
102 unsigned *length, R_RSA_PRIVATE_KEY * key);
103
104 int
105 R_VerifyInit(R_SIGNATURE_CTX * ctx, int digestAlgorithm);
106
107 int
108 R_VerifyUpdate(R_SIGNATURE_CTX * ctx, const uint8_t * data,
109 /* Length is an unsigned char according to rsaref.txt,
110 * but that must be a typo. */
111 unsigned length);
112
113 int
114 R_VerifyFinal(R_SIGNATURE_CTX * ctx,
115 uint8_t * signature,
116 unsigned length, R_RSA_PUBLIC_KEY * key);
117
118 #ifdef __cplusplus
119 }
120 #endif
121 #endif /* NETTLE_RSA_COMPAT_H_INCLUDED */