Patch to remove segfault on the exiting of a service.
[openais.git] / exec / crypto.h
blob09c221410509f03266118ff3df1f05ae5a9e0002
1 #ifndef CRYPTO_H_DEFINED
2 #define CRYPTO_H_DEFINED
4 #define DIGEST_SHA1 0
5 #define PRNG_SOBER 0
8 enum {
9 CRYPT_OK=0, /* Result OK */
10 CRYPT_ERROR, /* Generic Error */
11 CRYPT_NOP, /* Not a failure but no operation was performed */
13 CRYPT_INVALID_KEYSIZE, /* Invalid key size given */
14 CRYPT_INVALID_ROUNDS, /* Invalid number of rounds */
15 CRYPT_FAIL_TESTVECTOR, /* Algorithm failed test vectors */
17 CRYPT_BUFFER_OVERFLOW, /* Not enough space for output */
18 CRYPT_INVALID_PACKET, /* Invalid input packet given */
20 CRYPT_INVALID_PRNGSIZE, /* Invalid number of bits for a PRNG */
21 CRYPT_ERROR_READPRNG, /* Could not read enough from PRNG */
23 CRYPT_INVALID_CIPHER, /* Invalid cipher specified */
24 CRYPT_INVALID_HASH, /* Invalid hash specified */
25 CRYPT_INVALID_PRNG, /* Invalid PRNG specified */
27 CRYPT_MEM, /* Out of memory */
28 CRYPT_PK_TYPE_MISMATCH, /* Not equivalent types of PK keys */
29 CRYPT_PK_NOT_PRIVATE, /* Requires a private PK key */
31 CRYPT_INVALID_ARG, /* Generic invalid argument */
32 CRYPT_FILE_NOTFOUND, /* File Not Found */
34 CRYPT_PK_INVALID_TYPE, /* Invalid type of PK key */
35 CRYPT_PK_INVALID_SYSTEM,/* Invalid PK system specified */
36 CRYPT_PK_DUP, /* Duplicate key already in key ring */
37 CRYPT_PK_NOT_FOUND, /* Key not found in keyring */
38 CRYPT_PK_INVALID_SIZE, /* Invalid size input for PK parameters */
40 CRYPT_INVALID_PRIME_SIZE/* Invalid size of prime requested */
43 struct sha1_state {
44 unsigned long long length;
45 unsigned long state[5], curlen;
46 unsigned char buf[64];
48 typedef union Hash_state {
49 struct sha1_state sha1;
50 } hash_state;
52 struct _hash_descriptor {
53 char *name;
54 unsigned char ID;
55 unsigned long hashsize; /* digest output size in bytes */
56 unsigned long blocksize; /* the block size the hash uses */
57 unsigned char DER[64]; /* DER encoded identifier */
58 unsigned long DERlen; /* length of DER encoding */
59 void (*init)(hash_state *);
60 int (*process)(hash_state *, const unsigned char *, unsigned long);
61 int (*done)(hash_state *, unsigned char *);
62 int (*test)(void);
65 extern const struct _hash_descriptor *hash_descriptor[];
67 void sha1_init(hash_state * md);
68 int sha1_process(hash_state * md, const unsigned char *buf, unsigned long len);
69 int sha1_done(hash_state * md, unsigned char *hash);
70 int sha1_test(void);
72 int hash_memory(int hash, const unsigned char *data, unsigned long len, unsigned char *dst, unsigned long *outlen);
74 #define MAXBLOCKSIZE 128
75 typedef struct Hmac_state {
76 hash_state md;
77 int hash;
78 hash_state hashstate;
79 unsigned char key[MAXBLOCKSIZE];
80 } hmac_state;
82 int hmac_init(hmac_state *hmac, int hash, const unsigned char *key, unsigned long keylen);
83 int hmac_process(hmac_state *hmac, const unsigned char *buf, unsigned long len);
84 int hmac_done(hmac_state *hmac, unsigned char *hashOut, unsigned long *outlen);
85 int hmac_test(void);
86 int hmac_memory(int hash, const unsigned char *key, unsigned long keylen,
87 const unsigned char *data, unsigned long len,
88 unsigned char *dst, unsigned long *dstlen);
90 struct sober128_prng {
91 unsigned long R[17], /* Working storage for the shift register */
92 initR[17], /* saved register contents */
93 konst, /* key dependent constant */
94 sbuf; /* partial word encryption buffer */
96 int nbuf, /* number of part-word stream bits buffered */
97 flag, /* first add_entropy call or not? */
98 set; /* did we call add_entropy to set key? */
102 typedef union Prng_state {
103 struct sober128_prng sober128;
104 } prng_state;
106 struct _prng_descriptor {
107 char *name;
108 int export_size; /* size in bytes of exported state */
109 int (*start)(prng_state *);
110 int (*add_entropy)(const unsigned char *, unsigned long, prng_state *);
111 int (*ready)(prng_state *);
112 unsigned long (*read)(unsigned char *, unsigned long, prng_state *);
115 extern const struct _prng_descriptor *prng_descriptor[];
117 int sober128_start(prng_state *prng);
118 int sober128_add_entropy(const unsigned char *buf, unsigned long len, prng_state *prng);
119 int sober128_ready(prng_state *prng);
120 unsigned long sober128_read(unsigned char *buf, unsigned long len, prng_state *prng);
121 int sober128_done(prng_state *prng);
122 int sober128_export(unsigned char *out, unsigned long *outlen, prng_state *prng);
123 int sober128_import(const unsigned char *in, unsigned long inlen, prng_state *prng);
124 int sober128_test(void);
126 unsigned long rng_get_bytes(unsigned char *buf,
127 unsigned long len,
128 void (*callback)(void));
130 int rng_make_prng(int bits, int wprng, prng_state *prng, void (*callback)(void));
132 #endif /* CRYPTO_H_DEFINED */