1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci *
4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci */
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci/*
11e1051a39Sopenharmony_ci * RC2 low level APIs are deprecated for public use, but still ok for internal
12e1051a39Sopenharmony_ci * use.
13e1051a39Sopenharmony_ci */
14e1051a39Sopenharmony_ci#include "internal/deprecated.h"
15e1051a39Sopenharmony_ci
16e1051a39Sopenharmony_ci#include "cipher_rc2.h"
17e1051a39Sopenharmony_ci
18e1051a39Sopenharmony_cistatic int cipher_hw_rc2_initkey(PROV_CIPHER_CTX *ctx,
19e1051a39Sopenharmony_ci                                 const unsigned char *key, size_t keylen)
20e1051a39Sopenharmony_ci{
21e1051a39Sopenharmony_ci    PROV_RC2_CTX *rctx =  (PROV_RC2_CTX *)ctx;
22e1051a39Sopenharmony_ci    RC2_KEY *ks = &(rctx->ks.ks);
23e1051a39Sopenharmony_ci
24e1051a39Sopenharmony_ci    RC2_set_key(ks, (int)ctx->keylen, key, (int)rctx->key_bits);
25e1051a39Sopenharmony_ci    return 1;
26e1051a39Sopenharmony_ci}
27e1051a39Sopenharmony_ci
28e1051a39Sopenharmony_ci# define PROV_CIPHER_HW_rc2_mode(mode, UCMODE)                                 \
29e1051a39Sopenharmony_ciIMPLEMENT_CIPHER_HW_##UCMODE(mode, rc2, PROV_RC2_CTX, RC2_KEY,                 \
30e1051a39Sopenharmony_ci                             RC2_##mode)                                       \
31e1051a39Sopenharmony_cistatic const PROV_CIPHER_HW rc2_##mode = {                                     \
32e1051a39Sopenharmony_ci    cipher_hw_rc2_initkey,                                                     \
33e1051a39Sopenharmony_ci    cipher_hw_rc2_##mode##_cipher                                              \
34e1051a39Sopenharmony_ci};                                                                             \
35e1051a39Sopenharmony_ciconst PROV_CIPHER_HW *ossl_prov_cipher_hw_rc2_##mode(size_t keybits)           \
36e1051a39Sopenharmony_ci{                                                                              \
37e1051a39Sopenharmony_ci    return &rc2_##mode;                                                        \
38e1051a39Sopenharmony_ci}
39e1051a39Sopenharmony_ci
40e1051a39Sopenharmony_ciPROV_CIPHER_HW_rc2_mode(cbc, CBC)
41e1051a39Sopenharmony_ciPROV_CIPHER_HW_rc2_mode(ecb, ECB)
42e1051a39Sopenharmony_ciPROV_CIPHER_HW_rc2_mode(ofb64, OFB)
43e1051a39Sopenharmony_ciPROV_CIPHER_HW_rc2_mode(cfb64, CFB)
44