1ef78cef222a94b4abf1bf33bf0f540bb0945413
[openssl.git] / crypto / modes / modes.h
1 /* ====================================================================
2  * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
3  *
4  * Rights for redistribution and usage in source and binary
5  * forms are granted according to the OpenSSL license.
6  */
7
8 #include <stddef.h>
9
10 typedef void (*block128_f)(const unsigned char in[16],
11                         unsigned char out[16],
12                         const void *key);
13
14 typedef void (*cbc128_f)(const unsigned char *in, unsigned char *out,
15                         size_t len, const void *key,
16                         unsigned char ivec[16], int enc);
17
18 typedef void (*ctr128_f)(const unsigned char *in, unsigned char *out,
19                         size_t blocks, const void *key,
20                         const unsigned char ivec[16]);
21
22 void CRYPTO_cbc128_encrypt(const unsigned char *in, unsigned char *out,
23                         size_t len, const void *key,
24                         unsigned char ivec[16], block128_f block);
25 void CRYPTO_cbc128_decrypt(const unsigned char *in, unsigned char *out,
26                         size_t len, const void *key,
27                         unsigned char ivec[16], block128_f block);
28
29 void CRYPTO_ctr128_encrypt(const unsigned char *in, unsigned char *out,
30                         size_t len, const void *key,
31                         unsigned char ivec[16], unsigned char ecount_buf[16],
32                         unsigned int *num, block128_f block);
33
34 void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out,
35                         size_t len, const void *key,
36                         unsigned char ivec[16], unsigned char ecount_buf[16],
37                         unsigned int *num, ctr128_f ctr);
38
39 void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out,
40                         size_t len, const void *key,
41                         unsigned char ivec[16], int *num,
42                         block128_f block);
43
44 void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out,
45                         size_t len, const void *key,
46                         unsigned char ivec[16], int *num,
47                         int enc, block128_f block);
48 void CRYPTO_cfb128_8_encrypt(const unsigned char *in, unsigned char *out,
49                         size_t length, const void *key,
50                         unsigned char ivec[16], int *num,
51                         int enc, block128_f block);
52 void CRYPTO_cfb128_1_encrypt(const unsigned char *in, unsigned char *out,
53                         size_t bits, const void *key,
54                         unsigned char ivec[16], int *num,
55                         int enc, block128_f block);
56
57 size_t CRYPTO_cts128_encrypt_block(const unsigned char *in, unsigned char *out,
58                         size_t len, const void *key,
59                         unsigned char ivec[16], block128_f block);
60 size_t CRYPTO_cts128_encrypt(const unsigned char *in, unsigned char *out,
61                         size_t len, const void *key,
62                         unsigned char ivec[16], cbc128_f cbc);
63 size_t CRYPTO_cts128_decrypt_block(const unsigned char *in, unsigned char *out,
64                         size_t len, const void *key,
65                         unsigned char ivec[16], block128_f block);
66 size_t CRYPTO_cts128_decrypt(const unsigned char *in, unsigned char *out,
67                         size_t len, const void *key,
68                         unsigned char ivec[16], cbc128_f cbc);
69
70 size_t CRYPTO_nistcts128_encrypt_block(const unsigned char *in, unsigned char *out,
71                         size_t len, const void *key,
72                         unsigned char ivec[16], block128_f block);
73 size_t CRYPTO_nistcts128_encrypt(const unsigned char *in, unsigned char *out,
74                         size_t len, const void *key,
75                         unsigned char ivec[16], cbc128_f cbc);
76 size_t CRYPTO_nistcts128_decrypt_block(const unsigned char *in, unsigned char *out,
77                         size_t len, const void *key,
78                         unsigned char ivec[16], block128_f block);
79 size_t CRYPTO_nistcts128_decrypt(const unsigned char *in, unsigned char *out,
80                         size_t len, const void *key,
81                         unsigned char ivec[16], cbc128_f cbc);
82
83 typedef struct gcm128_context GCM128_CONTEXT;
84
85 GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block);
86 void CRYPTO_gcm128_init(GCM128_CONTEXT *ctx,void *key,block128_f block);
87 void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const unsigned char *iv,
88                         size_t len);
89 int CRYPTO_gcm128_aad(GCM128_CONTEXT *ctx, const unsigned char *aad,
90                         size_t len);
91 int CRYPTO_gcm128_encrypt(GCM128_CONTEXT *ctx,
92                         const unsigned char *in, unsigned char *out,
93                         size_t len);
94 int CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
95                         const unsigned char *in, unsigned char *out,
96                         size_t len);
97 int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx,
98                         const unsigned char *in, unsigned char *out,
99                         size_t len, ctr128_f stream);
100 int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx,
101                         const unsigned char *in, unsigned char *out,
102                         size_t len, ctr128_f stream);
103 int  CRYPTO_gcm128_finish(GCM128_CONTEXT *ctx,const unsigned char *tag,
104                         size_t len);
105 void  CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len);
106 void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx);
107
108 typedef struct xts128_context XTS128_CONTEXT;
109
110 int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char *iv,
111         const unsigned char *inp, unsigned char *out,
112         size_t len, int enc);