/src/openssl111/crypto/evp/e_rc5.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the OpenSSL license (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 |
8 | | */ |
9 | | |
10 | | #include <stdio.h> |
11 | | #include "internal/cryptlib.h" |
12 | | |
13 | | #ifndef OPENSSL_NO_RC5 |
14 | | |
15 | | # include <openssl/evp.h> |
16 | | # include "crypto/evp.h" |
17 | | # include <openssl/objects.h> |
18 | | # include "evp_local.h" |
19 | | # include <openssl/rc5.h> |
20 | | |
21 | | static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
22 | | const unsigned char *iv, int enc); |
23 | | static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr); |
24 | | |
25 | | typedef struct { |
26 | | int rounds; /* number of rounds */ |
27 | | RC5_32_KEY ks; /* key schedule */ |
28 | | } EVP_RC5_KEY; |
29 | | |
30 | 0 | # define data(ctx) EVP_C_DATA(EVP_RC5_KEY,ctx) |
31 | | |
32 | | IMPLEMENT_BLOCK_CIPHER(rc5_32_12_16, ks, RC5_32, EVP_RC5_KEY, NID_rc5, |
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) |
36 | | |
37 | | static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) |
38 | 0 | { |
39 | 0 | switch (type) { |
40 | 0 | case EVP_CTRL_INIT: |
41 | 0 | data(c)->rounds = RC5_12_ROUNDS; |
42 | 0 | return 1; |
43 | | |
44 | 0 | case EVP_CTRL_GET_RC5_ROUNDS: |
45 | 0 | *(int *)ptr = data(c)->rounds; |
46 | 0 | return 1; |
47 | | |
48 | 0 | case EVP_CTRL_SET_RC5_ROUNDS: |
49 | 0 | switch (arg) { |
50 | 0 | case RC5_8_ROUNDS: |
51 | 0 | case RC5_12_ROUNDS: |
52 | 0 | case RC5_16_ROUNDS: |
53 | 0 | data(c)->rounds = arg; |
54 | 0 | return 1; |
55 | | |
56 | 0 | default: |
57 | 0 | EVPerr(EVP_F_RC5_CTRL, EVP_R_UNSUPPORTED_NUMBER_OF_ROUNDS); |
58 | 0 | return 0; |
59 | 0 | } |
60 | | |
61 | 0 | default: |
62 | 0 | return -1; |
63 | 0 | } |
64 | 0 | } |
65 | | |
66 | | static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
67 | | const unsigned char *iv, int enc) |
68 | 0 | { |
69 | 0 | if (EVP_CIPHER_CTX_key_length(ctx) > 255) { |
70 | 0 | EVPerr(EVP_F_R_32_12_16_INIT_KEY, EVP_R_BAD_KEY_LENGTH); |
71 | 0 | return 0; |
72 | 0 | } |
73 | 0 | RC5_32_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), |
74 | 0 | key, data(ctx)->rounds); |
75 | 0 | return 1; |
76 | 0 | } |
77 | | |
78 | | #endif |