11cb0ef41Sopenharmony_ci/*
21cb0ef41Sopenharmony_ci * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
31cb0ef41Sopenharmony_ci *
41cb0ef41Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
51cb0ef41Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
61cb0ef41Sopenharmony_ci * in the file LICENSE in the source distribution or at
71cb0ef41Sopenharmony_ci * https://www.openssl.org/source/license.html
81cb0ef41Sopenharmony_ci */
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci/*
111cb0ef41Sopenharmony_ci * CAST low level APIs are deprecated for public use, but still ok for
121cb0ef41Sopenharmony_ci * internal use.
131cb0ef41Sopenharmony_ci */
141cb0ef41Sopenharmony_ci#include "internal/deprecated.h"
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci#include <stdio.h>
171cb0ef41Sopenharmony_ci#include "internal/cryptlib.h"
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci#ifndef OPENSSL_NO_CAST
201cb0ef41Sopenharmony_ci# include <openssl/evp.h>
211cb0ef41Sopenharmony_ci# include <openssl/objects.h>
221cb0ef41Sopenharmony_ci# include "crypto/evp.h"
231cb0ef41Sopenharmony_ci# include <openssl/cast.h>
241cb0ef41Sopenharmony_ci# include "evp_local.h"
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cistatic int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
271cb0ef41Sopenharmony_ci                         const unsigned char *iv, int enc);
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_citypedef struct {
301cb0ef41Sopenharmony_ci    CAST_KEY ks;
311cb0ef41Sopenharmony_ci} EVP_CAST_KEY;
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci# define data(ctx)       EVP_C_DATA(EVP_CAST_KEY,ctx)
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ciIMPLEMENT_BLOCK_CIPHER(cast5, ks, CAST, EVP_CAST_KEY,
361cb0ef41Sopenharmony_ci                       NID_cast5, 8, CAST_KEY_LENGTH, 8, 64,
371cb0ef41Sopenharmony_ci                       EVP_CIPH_VARIABLE_LENGTH, cast_init_key, NULL,
381cb0ef41Sopenharmony_ci                       EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL)
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_cistatic int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
411cb0ef41Sopenharmony_ci                         const unsigned char *iv, int enc)
421cb0ef41Sopenharmony_ci{
431cb0ef41Sopenharmony_ci    int keylen = EVP_CIPHER_CTX_get_key_length(ctx);
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci    if (keylen <= 0)
461cb0ef41Sopenharmony_ci        return 0;
471cb0ef41Sopenharmony_ci    CAST_set_key(&data(ctx)->ks, keylen, key);
481cb0ef41Sopenharmony_ci    return 1;
491cb0ef41Sopenharmony_ci}
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci#endif
52