]>
Commit | Line | Data |
---|---|---|
62867571 | 1 | /* |
33388b44 | 2 | * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. |
58964a49 | 3 | * |
4a8b0c55 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
62867571 RS |
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 | |
58964a49 RE |
8 | */ |
9 | ||
62c3fed0 P |
10 | /* |
11 | * RC5 low level APIs are deprecated for public use, but still ok for internal | |
12 | * use. | |
13 | */ | |
14 | #include "internal/deprecated.h" | |
15 | ||
58964a49 | 16 | #include <stdio.h> |
b39fc560 | 17 | #include "internal/cryptlib.h" |
f1185145 RL |
18 | |
19 | #ifndef OPENSSL_NO_RC5 | |
20 | ||
0f113f3e | 21 | # include <openssl/evp.h> |
25f2138b | 22 | # include "crypto/evp.h" |
0f113f3e | 23 | # include <openssl/objects.h> |
706457b7 | 24 | # include "evp_local.h" |
0f113f3e | 25 | # include <openssl/rc5.h> |
58964a49 | 26 | |
1921eaad | 27 | static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
0f113f3e | 28 | const unsigned char *iv, int enc); |
49528751 | 29 | static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr); |
57ae2e24 | 30 | |
0f113f3e MC |
31 | typedef struct { |
32 | int rounds; /* number of rounds */ | |
33 | RC5_32_KEY ks; /* key schedule */ | |
34 | } EVP_RC5_KEY; | |
49528751 | 35 | |
0f113f3e | 36 | # define data(ctx) EVP_C_DATA(EVP_RC5_KEY,ctx) |
57ae2e24 | 37 | |
dbad1690 | 38 | IMPLEMENT_BLOCK_CIPHER(rc5_32_12_16, ks, RC5_32, EVP_RC5_KEY, NID_rc5, |
0f113f3e MC |
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) | |
58964a49 | 42 | |
49528751 | 43 | static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) |
0f113f3e MC |
44 | { |
45 | switch (type) { | |
46 | case EVP_CTRL_INIT: | |
47 | data(c)->rounds = RC5_12_ROUNDS; | |
48 | return 1; | |
49 | ||
50 | case EVP_CTRL_GET_RC5_ROUNDS: | |
51 | *(int *)ptr = data(c)->rounds; | |
52 | return 1; | |
49528751 | 53 | |
0f113f3e MC |
54 | case EVP_CTRL_SET_RC5_ROUNDS: |
55 | switch (arg) { | |
56 | case RC5_8_ROUNDS: | |
57 | case RC5_12_ROUNDS: | |
58 | case RC5_16_ROUNDS: | |
59 | data(c)->rounds = arg; | |
60 | return 1; | |
49528751 | 61 | |
0f113f3e | 62 | default: |
5898b8eb | 63 | EVPerr(EVP_F_RC5_CTRL, EVP_R_UNSUPPORTED_NUMBER_OF_ROUNDS); |
0f113f3e MC |
64 | return 0; |
65 | } | |
49528751 | 66 | |
0f113f3e MC |
67 | default: |
68 | return -1; | |
69 | } | |
70 | } | |
49528751 | 71 | |
1921eaad | 72 | static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
0f113f3e MC |
73 | const unsigned char *iv, int enc) |
74 | { | |
792cb4ee MC |
75 | if (EVP_CIPHER_CTX_key_length(ctx) > 255) { |
76 | EVPerr(EVP_F_R_32_12_16_INIT_KEY, EVP_R_BAD_KEY_LENGTH); | |
77 | return 0; | |
78 | } | |
9a131ad7 MC |
79 | return RC5_32_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), |
80 | key, data(ctx)->rounds); | |
0f113f3e | 81 | } |
58964a49 RE |
82 | |
83 | #endif |