]>
Commit | Line | Data |
---|---|---|
62867571 RS |
1 | /* |
2 | * Copyright 1995-2016 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 | ||
58964a49 | 10 | #include <stdio.h> |
b39fc560 | 11 | #include "internal/cryptlib.h" |
f1185145 RL |
12 | |
13 | #ifndef OPENSSL_NO_RC5 | |
14 | ||
0f113f3e | 15 | # include <openssl/evp.h> |
25f2138b | 16 | # include "crypto/evp.h" |
0f113f3e | 17 | # include <openssl/objects.h> |
706457b7 | 18 | # include "evp_local.h" |
0f113f3e | 19 | # include <openssl/rc5.h> |
58964a49 | 20 | |
1921eaad | 21 | static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
0f113f3e | 22 | const unsigned char *iv, int enc); |
49528751 | 23 | static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr); |
57ae2e24 | 24 | |
0f113f3e MC |
25 | typedef struct { |
26 | int rounds; /* number of rounds */ | |
27 | RC5_32_KEY ks; /* key schedule */ | |
28 | } EVP_RC5_KEY; | |
49528751 | 29 | |
0f113f3e | 30 | # define data(ctx) EVP_C_DATA(EVP_RC5_KEY,ctx) |
57ae2e24 | 31 | |
dbad1690 | 32 | IMPLEMENT_BLOCK_CIPHER(rc5_32_12_16, ks, RC5_32, EVP_RC5_KEY, NID_rc5, |
0f113f3e MC |
33 | 8, RC5_32_KEY_LENGTH, 8, 64, |
34 | EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT, | |
35 | r_32_12_16_init_key, NULL, NULL, NULL, rc5_ctrl) | |
58964a49 | 36 | |
49528751 | 37 | static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) |
0f113f3e MC |
38 | { |
39 | switch (type) { | |
40 | case EVP_CTRL_INIT: | |
41 | data(c)->rounds = RC5_12_ROUNDS; | |
42 | return 1; | |
43 | ||
44 | case EVP_CTRL_GET_RC5_ROUNDS: | |
45 | *(int *)ptr = data(c)->rounds; | |
46 | return 1; | |
49528751 | 47 | |
0f113f3e MC |
48 | case EVP_CTRL_SET_RC5_ROUNDS: |
49 | switch (arg) { | |
50 | case RC5_8_ROUNDS: | |
51 | case RC5_12_ROUNDS: | |
52 | case RC5_16_ROUNDS: | |
53 | data(c)->rounds = arg; | |
54 | return 1; | |
49528751 | 55 | |
0f113f3e | 56 | default: |
5898b8eb | 57 | EVPerr(EVP_F_RC5_CTRL, EVP_R_UNSUPPORTED_NUMBER_OF_ROUNDS); |
0f113f3e MC |
58 | return 0; |
59 | } | |
49528751 | 60 | |
0f113f3e MC |
61 | default: |
62 | return -1; | |
63 | } | |
64 | } | |
49528751 | 65 | |
1921eaad | 66 | static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
0f113f3e MC |
67 | const unsigned char *iv, int enc) |
68 | { | |
792cb4ee MC |
69 | if (EVP_CIPHER_CTX_key_length(ctx) > 255) { |
70 | EVPerr(EVP_F_R_32_12_16_INIT_KEY, EVP_R_BAD_KEY_LENGTH); | |
71 | return 0; | |
72 | } | |
9a131ad7 MC |
73 | return RC5_32_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), |
74 | key, data(ctx)->rounds); | |
0f113f3e | 75 | } |
58964a49 RE |
76 | |
77 | #endif |