2 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 * RC5 low level APIs are deprecated for public use, but still ok for internal
14 #include "internal/deprecated.h"
17 #include "internal/cryptlib.h"
19 #ifndef OPENSSL_NO_RC5
21 # include <openssl/evp.h>
22 # include "crypto/evp.h"
23 # include <openssl/objects.h>
24 # include "evp_local.h"
25 # include <openssl/rc5.h>
27 static int r_32_12_16_init_key(EVP_CIPHER_CTX
*ctx
, const unsigned char *key
,
28 const unsigned char *iv
, int enc
);
29 static int rc5_ctrl(EVP_CIPHER_CTX
*c
, int type
, int arg
, void *ptr
);
32 int rounds
; /* number of rounds */
33 RC5_32_KEY ks
; /* key schedule */
36 # define data(ctx) EVP_C_DATA(EVP_RC5_KEY,ctx)
38 IMPLEMENT_BLOCK_CIPHER(rc5_32_12_16
, ks
, RC5_32
, EVP_RC5_KEY
, NID_rc5
,
39 8, RC5_32_KEY_LENGTH
, 8, 64,
40 EVP_CIPH_VARIABLE_LENGTH
| EVP_CIPH_CTRL_INIT
,
41 r_32_12_16_init_key
, NULL
, NULL
, NULL
, rc5_ctrl
)
43 static int rc5_ctrl(EVP_CIPHER_CTX
*c
, int type
, int arg
, void *ptr
)
47 data(c
)->rounds
= RC5_12_ROUNDS
;
50 case EVP_CTRL_GET_RC5_ROUNDS
:
51 *(int *)ptr
= data(c
)->rounds
;
54 case EVP_CTRL_SET_RC5_ROUNDS
:
59 data(c
)->rounds
= arg
;
63 EVPerr(EVP_F_RC5_CTRL
, EVP_R_UNSUPPORTED_NUMBER_OF_ROUNDS
);
72 static int r_32_12_16_init_key(EVP_CIPHER_CTX
*ctx
, const unsigned char *key
,
73 const unsigned char *iv
, int enc
)
75 if (EVP_CIPHER_CTX_key_length(ctx
) > 255) {
76 EVPerr(EVP_F_R_32_12_16_INIT_KEY
, EVP_R_BAD_KEY_LENGTH
);
79 return RC5_32_set_key(&data(ctx
)->ks
, EVP_CIPHER_CTX_key_length(ctx
),
80 key
, data(ctx
)->rounds
);