Monero
Loading...
Searching...
No Matches
oaes_lib.h
Go to the documentation of this file.
1/*
2 * ---------------------------------------------------------------------------
3 * OpenAES License
4 * ---------------------------------------------------------------------------
5 * Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 * ---------------------------------------------------------------------------
29 */
30
31#ifndef _OAES_LIB_H
32#define _OAES_LIB_H
33
34#include <stdint.h>
35#include <stdlib.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41#ifdef _WIN32
42# ifdef OAES_SHARED
43# ifdef oaes_lib_EXPORTS
44# define OAES_API __declspec(dllexport)
45# else
46# define OAES_API __declspec(dllimport)
47# endif
48# else
49# define OAES_API
50# endif
51#else
52# define OAES_API
53#endif // WIN32
54
55#define OAES_VERSION "0.8.1"
56#define OAES_BLOCK_SIZE 16
57
58typedef void OAES_CTX;
59
76
77/*
78 * oaes_set_option() takes one of these values for its [option] parameter
79 * some options accept either an optional or a required [value] parameter
80 */
81// no option
82#define OAES_OPTION_NONE 0
83// enable ECB mode, disable CBC mode
84#define OAES_OPTION_ECB 1
85// enable CBC mode, disable ECB mode
86// value is optional, may pass uint8_t iv[OAES_BLOCK_SIZE] to specify
87// the value of the initialization vector, iv
88#define OAES_OPTION_CBC 2
89
90#ifdef OAES_DEBUG
91typedef int ( * oaes_step_cb ) (
93 const char * step_name,
94 int step_count,
95 void * user_data );
96// enable state stepping mode
97// value is required, must pass oaes_step_cb to receive the state at each step
98#define OAES_OPTION_STEP_ON 4
99// disable state stepping mode
100#define OAES_OPTION_STEP_OFF 8
101#endif // OAES_DEBUG
102
104
114
115typedef struct _oaes_ctx
116{
117#ifdef OAES_HAVE_ISAAC
118 randctx * rctx;
119#endif // OAES_HAVE_ISAAC
120
121#ifdef OAES_DEBUG
122 oaes_step_cb step_cb;
123#endif // OAES_DEBUG
124
129/*
130 * // usage:
131 *
132 * OAES_CTX * ctx = oaes_alloc();
133 * .
134 * .
135 * .
136 * {
137 * oaes_gen_key_xxx( ctx );
138 * {
139 * oaes_key_export( ctx, _buf, &_buf_len );
140 * // or
141 * oaes_key_export_data( ctx, _buf, &_buf_len );\
142 * }
143 * }
144 * // or
145 * {
146 * oaes_key_import( ctx, _buf, _buf_len );
147 * // or
148 * oaes_key_import_data( ctx, _buf, _buf_len );
149 * }
150 * .
151 * .
152 * .
153 * oaes_encrypt( ctx, m, m_len, c, &c_len );
154 * .
155 * .
156 * .
157 * oaes_decrypt( ctx, c, c_len, m, &m_len );
158 * .
159 * .
160 * .
161 * oaes_free( &ctx );
162 */
163
165
167
169 OAES_OPTION option, const void * value );
170
172
174
176
177// export key with header information
178// set data == NULL to get the required data_len
180 uint8_t * data, size_t * data_len );
181
182// directly export the data from key
183// set data == NULL to get the required data_len
185 uint8_t * data, size_t * data_len );
186
187// import key with header information
189 const uint8_t * data, size_t data_len );
190
191// directly import data into key
193 const uint8_t * data, size_t data_len );
194
195// set c == NULL to get the required c_len
197 const uint8_t * m, size_t m_len, uint8_t * c, size_t * c_len );
198
199// set m == NULL to get the required m_len
201 const uint8_t * c, size_t c_len, uint8_t * m, size_t * m_len );
202
203// set buf == NULL to get the required buf_len
205 char * buf, size_t * buf_len, const uint8_t * data, size_t data_len );
206
208
210
211#ifdef __cplusplus
212}
213#endif
214
215#endif // _OAES_LIB_H
const char * key
Definition hmac_keccak.cpp:40
OAES_API OAES_RET oaes_key_export(OAES_CTX *ctx, uint8_t *data, size_t *data_len)
Definition oaes_lib.c:689
OAES_API OAES_CTX * oaes_alloc(void)
Definition oaes_lib.c:894
OAES_API OAES_RET oaes_key_import_data(OAES_CTX *ctx, const uint8_t *data, size_t data_len)
Definition oaes_lib.c:842
OAES_API OAES_RET oaes_encrypt(OAES_CTX *ctx, const uint8_t *m, size_t m_len, uint8_t *c, size_t *c_len)
Definition oaes_lib.c:1258
OAES_API OAES_RET oaes_free(OAES_CTX **ctx)
Definition oaes_lib.c:934
#define OAES_API
Definition oaes_lib.h:52
OAES_API OAES_RET oaes_key_gen_128(OAES_CTX *ctx)
Definition oaes_lib.c:674
OAES_API OAES_RET oaes_key_gen_256(OAES_CTX *ctx)
Definition oaes_lib.c:684
void OAES_CTX
Definition oaes_lib.h:58
OAES_API OAES_RET oaes_key_gen_192(OAES_CTX *ctx)
Definition oaes_lib.c:679
OAES_API OAES_RET oaes_sprintf(char *buf, size_t *buf_len, const uint8_t *data, size_t data_len)
Definition oaes_lib.c:440
uint16_t OAES_OPTION
Definition oaes_lib.h:103
OAES_API OAES_RET oaes_set_option(OAES_CTX *ctx, OAES_OPTION option, const void *value)
Definition oaes_lib.c:961
OAES_API OAES_RET oaes_encryption_round(const uint8_t *key, uint8_t *c)
Definition oaes_lib.c:1457
OAES_API OAES_RET oaes_key_import(OAES_CTX *ctx, const uint8_t *data, size_t data_len)
Definition oaes_lib.c:752
OAES_API OAES_RET oaes_key_export_data(OAES_CTX *ctx, uint8_t *data, size_t *data_len)
Definition oaes_lib.c:723
#define OAES_BLOCK_SIZE
Definition oaes_lib.h:56
OAES_API OAES_RET oaes_pseudo_encrypt_ecb(OAES_CTX *ctx, uint8_t *c)
Definition oaes_lib.c:1487
struct _oaes_key oaes_key
OAES_API OAES_RET oaes_decrypt(OAES_CTX *ctx, const uint8_t *c, size_t c_len, uint8_t *m, size_t *m_len)
Definition oaes_lib.c:1330
struct _oaes_ctx oaes_ctx
OAES_RET
Definition oaes_lib.h:61
@ OAES_RET_ARG5
Definition oaes_lib.h:69
@ OAES_RET_MEM
Definition oaes_lib.h:71
@ OAES_RET_UNKNOWN
Definition oaes_lib.h:64
@ OAES_RET_BUF
Definition oaes_lib.h:72
@ OAES_RET_ARG3
Definition oaes_lib.h:67
@ OAES_RET_FIRST
Definition oaes_lib.h:62
@ OAES_RET_ARG2
Definition oaes_lib.h:66
@ OAES_RET_NOKEY
Definition oaes_lib.h:70
@ OAES_RET_SUCCESS
Definition oaes_lib.h:63
@ OAES_RET_ARG4
Definition oaes_lib.h:68
@ OAES_RET_ARG1
Definition oaes_lib.h:65
@ OAES_RET_COUNT
Definition oaes_lib.h:74
@ OAES_RET_HEADER
Definition oaes_lib.h:73
const GenericPointer< typename T::ValueType > T2 value
Definition pointer.h:1225
const char * buf
Definition slow_memmem.cpp:73
unsigned short uint16_t
Definition stdint.h:125
unsigned char uint8_t
Definition stdint.h:124
Definition oaes_lib.h:116
oaes_key * key
Definition oaes_lib.h:125
OAES_OPTION options
Definition oaes_lib.h:126
uint8_t iv[OAES_BLOCK_SIZE]
Definition oaes_lib.h:127
Definition oaes_lib.h:106
size_t data_len
Definition oaes_lib.h:107
size_t num_keys
Definition oaes_lib.h:111
size_t key_base
Definition oaes_lib.h:112
size_t exp_data_len
Definition oaes_lib.h:109
uint8_t * data
Definition oaes_lib.h:108
uint8_t * exp_data
Definition oaes_lib.h:110
Definition options.h:95
Definition blake256.h:36
std::string data
Definition base58.cpp:37