summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/e_aes.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/evp/e_aes.c (renamed from src/lib/libcrypto/engine/hw_sureware_err.h)102
1 files changed, 64 insertions, 38 deletions
diff --git a/src/lib/libcrypto/engine/hw_sureware_err.h b/src/lib/libcrypto/evp/e_aes.c
index bc52af5e05..bd6c0a3a62 100644
--- a/src/lib/libcrypto/engine/hw_sureware_err.h
+++ b/src/lib/libcrypto/evp/e_aes.c
@@ -46,49 +46,75 @@
46 * OF THE POSSIBILITY OF SUCH DAMAGE. 46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ==================================================================== 47 * ====================================================================
48 * 48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */ 49 */
54 50
55#ifndef HEADER_SUREWARE_ERR_H 51#include <openssl/opensslconf.h>
56#define HEADER_SUREWARE_ERR_H 52#ifndef OPENSSL_NO_AES
53#include <openssl/evp.h>
54#include <openssl/err.h>
55#include <string.h>
56#include <assert.h>
57#include <openssl/aes.h>
58#include "evp_locl.h"
57 59
58/* BEGIN ERROR CODES */ 60static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
59/* The following lines are auto generated by the script mkerr.pl. Any changes 61 const unsigned char *iv, int enc);
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_SUREWARE_strings(void);
63static void ERR_unload_SUREWARE_strings(void);
64static void ERR_SUREWARE_error(int function, int reason, char *file, int line);
65#define SUREWAREerr(f,r) ERR_SUREWARE_error((f),(r),__FILE__,__LINE__)
66 62
67/* Error codes for the SUREWARE functions. */ 63typedef struct
64 {
65 AES_KEY ks;
66 } EVP_AES_KEY;
68 67
69/* Function codes. */ 68#define data(ctx) EVP_C_DATA(EVP_AES_KEY,ctx)
70#define SUREWARE_F_SUREWAREHK_CTRL 100
71#define SUREWARE_F_SUREWAREHK_DSA_DO_SIGN 101
72#define SUREWARE_F_SUREWAREHK_EX_FREE 102
73#define SUREWARE_F_SUREWAREHK_FINISH 103
74#define SUREWARE_F_SUREWAREHK_INIT 104
75#define SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY 105
76#define SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY 106
77#define SUREWARE_F_SUREWAREHK_MOD_EXP 107
78#define SUREWARE_F_SUREWAREHK_RAND_BYTES 108
79#define SUREWARE_F_SUREWAREHK_RAND_SEED 109
80#define SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC 110
81#define SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC 111
82 69
83/* Reason codes. */ 70IMPLEMENT_BLOCK_CIPHER(aes_128, ks, AES, EVP_AES_KEY,
84#define SUREWARE_R_BIO_WAS_FREED 100 71 NID_aes_128, 16, 16, 16, 128,
85#define SUREWARE_R_MISSING_KEY_COMPONENTS 105 72 0, aes_init_key, NULL,
86#define SUREWARE_R_REQUEST_FAILED 101 73 EVP_CIPHER_set_asn1_iv,
87#define SUREWARE_R_REQUEST_FALLBACK 102 74 EVP_CIPHER_get_asn1_iv,
88#define SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL 103 75 NULL)
89#define SUREWARE_R_UNIT_FAILURE 104 76IMPLEMENT_BLOCK_CIPHER(aes_192, ks, AES, EVP_AES_KEY,
77 NID_aes_192, 16, 24, 16, 128,
78 0, aes_init_key, NULL,
79 EVP_CIPHER_set_asn1_iv,
80 EVP_CIPHER_get_asn1_iv,
81 NULL)
82IMPLEMENT_BLOCK_CIPHER(aes_256, ks, AES, EVP_AES_KEY,
83 NID_aes_256, 16, 32, 16, 128,
84 0, aes_init_key, NULL,
85 EVP_CIPHER_set_asn1_iv,
86 EVP_CIPHER_get_asn1_iv,
87 NULL)
88
89#define IMPLEMENT_AES_CFBR(ksize,cbits) IMPLEMENT_CFBR(aes,AES,EVP_AES_KEY,ks,ksize,cbits,16)
90
91IMPLEMENT_AES_CFBR(128,1)
92IMPLEMENT_AES_CFBR(192,1)
93IMPLEMENT_AES_CFBR(256,1)
94
95IMPLEMENT_AES_CFBR(128,8)
96IMPLEMENT_AES_CFBR(192,8)
97IMPLEMENT_AES_CFBR(256,8)
98
99static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
100 const unsigned char *iv, int enc)
101 {
102 int ret;
103
104 if ((ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_CFB_MODE
105 || (ctx->cipher->flags & EVP_CIPH_MODE) == EVP_CIPH_OFB_MODE
106 || enc)
107 ret=AES_set_encrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
108 else
109 ret=AES_set_decrypt_key(key, ctx->key_len * 8, ctx->cipher_data);
110
111 if(ret < 0)
112 {
113 EVPerr(EVP_F_AES_INIT_KEY,EVP_R_AES_KEY_SETUP_FAILED);
114 return 0;
115 }
116
117 return 1;
118 }
90 119
91#ifdef __cplusplus
92}
93#endif
94#endif 120#endif