summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/e_rc5.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp/e_rc5.c')
-rw-r--r--src/lib/libcrypto/evp/e_rc5.c65
1 files changed, 36 insertions, 29 deletions
diff --git a/src/lib/libcrypto/evp/e_rc5.c b/src/lib/libcrypto/evp/e_rc5.c
index 5885f1826b..3c7713b181 100644
--- a/src/lib/libcrypto/evp/e_rc5.c
+++ b/src/lib/libcrypto/evp/e_rc5.c
@@ -56,62 +56,69 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_RC5 59#ifndef OPENSSL_NO_RC5
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include <openssl/evp.h> 63#include <openssl/evp.h>
64#include <openssl/objects.h> 64#include <openssl/objects.h>
65#include "evp_locl.h" 65#include "evp_locl.h"
66#include <openssl/rc5.h>
66 67
67static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 68static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68 const unsigned char *iv,int enc); 69 const unsigned char *iv,int enc);
69static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr); 70static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
70 71
71IMPLEMENT_BLOCK_CIPHER(rc5_32_12_16, rc5.ks, RC5_32, rc5, NID_rc5, 72typedef struct
72 8, EVP_RC5_32_12_16_KEY_SIZE, 8, 73 {
73 EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT, 74 int rounds; /* number of rounds */
74 r_32_12_16_init_key, NULL, 75 RC5_32_KEY ks; /* key schedule */
75 NULL, NULL, rc5_ctrl) 76 } EVP_RC5_KEY;
76 77
78#define data(ctx) EVP_C_DATA(EVP_RC5_KEY,ctx)
77 79
80IMPLEMENT_BLOCK_CIPHER(rc5_32_12_16, ks, RC5_32, EVP_RC5_KEY, NID_rc5,
81 8, RC5_32_KEY_LENGTH, 8, 64,
82 EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
83 r_32_12_16_init_key, NULL,
84 NULL, NULL, rc5_ctrl)
78 85
79static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) 86static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
80 { 87 {
81 switch(type) { 88 switch(type)
82 89 {
83 case EVP_CTRL_INIT: 90 case EVP_CTRL_INIT:
84 c->c.rc5.rounds = RC5_12_ROUNDS; 91 data(c)->rounds = RC5_12_ROUNDS;
85 return 1; 92 return 1;
86 93
87 case EVP_CTRL_GET_RC5_ROUNDS: 94 case EVP_CTRL_GET_RC5_ROUNDS:
88 *(int *)ptr = c->c.rc5.rounds; 95 *(int *)ptr = data(c)->rounds;
89 return 1; 96 return 1;
90
91 97
92 case EVP_CTRL_SET_RC5_ROUNDS: 98 case EVP_CTRL_SET_RC5_ROUNDS:
93 switch(arg) { 99 switch(arg)
94 case RC5_8_ROUNDS: 100 {
95 case RC5_12_ROUNDS: 101 case RC5_8_ROUNDS:
96 case RC5_16_ROUNDS: 102 case RC5_12_ROUNDS:
97 c->c.rc5.rounds = arg; 103 case RC5_16_ROUNDS:
98 return 1; 104 data(c)->rounds = arg;
105 return 1;
99 106
100 default: 107 default:
101 EVPerr(EVP_F_RC5_CTRL, EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS); 108 EVPerr(EVP_F_RC5_CTRL, EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS);
102 return 0; 109 return 0;
103 } 110 }
104 111
105 default: 112 default:
106 return -1; 113 return -1;
107 } 114 }
108 } 115 }
109 116
110static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 117static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
111 const unsigned char *iv, int enc) 118 const unsigned char *iv, int enc)
112 { 119 {
113 RC5_32_set_key(&(ctx->c.rc5.ks),EVP_CIPHER_CTX_key_length(ctx), 120 RC5_32_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
114 key,ctx->c.rc5.rounds); 121 key,data(ctx)->rounds);
115 return 1; 122 return 1;
116 } 123 }
117 124