Coverage Report

Created: 2025-06-13 06:57

/src/openssl/crypto/evp/e_rc5.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
3
 *
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
8
 */
9
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
16
#include <stdio.h>
17
#include "internal/cryptlib.h"
18
19
#ifndef OPENSSL_NO_RC5
20
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>
26
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);
30
31
typedef struct {
32
    int rounds;                 /* number of rounds */
33
    RC5_32_KEY ks;              /* key schedule */
34
} EVP_RC5_KEY;
35
36
0
# define data(ctx)       EVP_C_DATA(EVP_RC5_KEY,ctx)
37
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)
42
43
static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
44
0
{
45
0
    switch (type) {
46
0
    case EVP_CTRL_INIT:
47
0
        data(c)->rounds = RC5_12_ROUNDS;
48
0
        return 1;
49
50
0
    case EVP_CTRL_GET_RC5_ROUNDS:
51
0
        *(int *)ptr = data(c)->rounds;
52
0
        return 1;
53
54
0
    case EVP_CTRL_SET_RC5_ROUNDS:
55
0
        switch (arg) {
56
0
        case RC5_8_ROUNDS:
57
0
        case RC5_12_ROUNDS:
58
0
        case RC5_16_ROUNDS:
59
0
            data(c)->rounds = arg;
60
0
            return 1;
61
62
0
        default:
63
0
            ERR_raise(ERR_LIB_EVP, EVP_R_UNSUPPORTED_NUMBER_OF_ROUNDS);
64
0
            return 0;
65
0
        }
66
67
0
    default:
68
0
        return -1;
69
0
    }
70
0
}
71
72
static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
73
                               const unsigned char *iv, int enc)
74
0
{
75
0
    const int key_len = EVP_CIPHER_CTX_get_key_length(ctx);
76
77
0
    if (key_len > 255 || key_len < 0) {
78
0
        ERR_raise(ERR_LIB_EVP, EVP_R_BAD_KEY_LENGTH);
79
0
        return 0;
80
0
    }
81
0
    return RC5_32_set_key(&data(ctx)->ks, key_len, key, data(ctx)->rounds);
82
0
}
83
84
#endif