2016-05-18 02:24:46 +08:00
|
|
|
/*
|
2021-04-08 20:04:41 +08:00
|
|
|
* Copyright 2006-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2006-06-11 09:09:07 +08:00
|
|
|
*
|
2018-12-06 20:40:06 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:24:46 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2006-06-11 09:09:07 +08:00
|
|
|
*/
|
|
|
|
|
2020-01-02 23:22:19 +08:00
|
|
|
/*
|
|
|
|
* Camellia low level APIs are deprecated for public use, but still ok for
|
|
|
|
* internal use.
|
|
|
|
*/
|
|
|
|
#include "internal/deprecated.h"
|
|
|
|
|
2006-06-11 09:09:07 +08:00
|
|
|
#include <openssl/opensslconf.h>
|
2016-02-01 02:08:23 +08:00
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/err.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <openssl/camellia.h>
|
|
|
|
#include "crypto/evp.h"
|
|
|
|
#include "crypto/modes.h"
|
|
|
|
#include "crypto/cmll_platform.h"
|
2020-07-03 05:12:33 +08:00
|
|
|
#include "evp_local.h"
|
2006-06-11 09:09:07 +08:00
|
|
|
|
|
|
|
static int camellia_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
|
|
|
const unsigned char *iv, int enc);
|
|
|
|
|
|
|
|
/* Camellia subkey Structure */
|
|
|
|
typedef struct {
|
|
|
|
CAMELLIA_KEY ks;
|
2012-10-12 02:35:18 +08:00
|
|
|
block128_f block;
|
|
|
|
union {
|
|
|
|
cbc128_f cbc;
|
|
|
|
ctr128_f ctr;
|
|
|
|
} stream;
|
2006-06-11 09:09:07 +08:00
|
|
|
} EVP_CAMELLIA_KEY;
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
#define MAXBITCHUNK ((size_t)1<<(sizeof(size_t)*8-4))
|
2012-10-12 02:35:18 +08:00
|
|
|
|
2006-06-11 09:09:07 +08:00
|
|
|
/* Attribute operation for Camellia */
|
2020-03-06 01:50:31 +08:00
|
|
|
#define data(ctx) EVP_C_DATA(EVP_CAMELLIA_KEY,ctx)
|
2006-06-11 09:09:07 +08:00
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
#if defined(AES_ASM) && (defined(__sparc) || defined(__sparc__))
|
2012-10-12 02:35:18 +08:00
|
|
|
/* ---------^^^ this is not a typo, just a way to detect that
|
|
|
|
* assembler support was in general requested... */
|
2021-07-07 23:47:06 +08:00
|
|
|
# include "crypto/sparc_arch.h"
|
2012-10-12 02:35:18 +08:00
|
|
|
|
|
|
|
static int cmll_t4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
|
|
|
const unsigned char *iv, int enc)
|
|
|
|
{
|
|
|
|
int ret, mode, bits;
|
2016-03-07 18:17:27 +08:00
|
|
|
EVP_CAMELLIA_KEY *dat =
|
|
|
|
(EVP_CAMELLIA_KEY *)EVP_CIPHER_CTX_get_cipher_data(ctx);
|
2015-01-22 11:40:55 +08:00
|
|
|
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
mode = EVP_CIPHER_CTX_get_mode(ctx);
|
|
|
|
bits = EVP_CIPHER_CTX_get_key_length(ctx) * 8;
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2012-10-12 02:35:18 +08:00
|
|
|
cmll_t4_set_key(key, bits, &dat->ks);
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2012-10-12 02:35:18 +08:00
|
|
|
if ((mode == EVP_CIPH_ECB_MODE || mode == EVP_CIPH_CBC_MODE)
|
|
|
|
&& !enc) {
|
|
|
|
ret = 0;
|
|
|
|
dat->block = (block128_f) cmll_t4_decrypt;
|
|
|
|
switch (bits) {
|
|
|
|
case 128:
|
|
|
|
dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
|
|
|
|
(cbc128_f) cmll128_t4_cbc_decrypt : NULL;
|
|
|
|
break;
|
|
|
|
case 192:
|
|
|
|
case 256:
|
|
|
|
dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
|
|
|
|
(cbc128_f) cmll256_t4_cbc_decrypt : NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = 0;
|
|
|
|
dat->block = (block128_f) cmll_t4_encrypt;
|
|
|
|
switch (bits) {
|
|
|
|
case 128:
|
|
|
|
if (mode == EVP_CIPH_CBC_MODE)
|
|
|
|
dat->stream.cbc = (cbc128_f) cmll128_t4_cbc_encrypt;
|
|
|
|
else if (mode == EVP_CIPH_CTR_MODE)
|
|
|
|
dat->stream.ctr = (ctr128_f) cmll128_t4_ctr32_encrypt;
|
|
|
|
else
|
|
|
|
dat->stream.cbc = NULL;
|
|
|
|
break;
|
|
|
|
case 192:
|
|
|
|
case 256:
|
|
|
|
if (mode == EVP_CIPH_CBC_MODE)
|
|
|
|
dat->stream.cbc = (cbc128_f) cmll256_t4_cbc_encrypt;
|
|
|
|
else if (mode == EVP_CIPH_CTR_MODE)
|
|
|
|
dat->stream.ctr = (ctr128_f) cmll256_t4_ctr32_encrypt;
|
|
|
|
else
|
|
|
|
dat->stream.cbc = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2012-10-12 02:35:18 +08:00
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2012-10-12 02:35:18 +08:00
|
|
|
if (ret < 0) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_EVP, EVP_R_CAMELLIA_KEY_SETUP_FAILED);
|
2012-10-12 02:35:18 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2012-10-12 02:35:18 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
# define cmll_t4_cbc_cipher camellia_cbc_cipher
|
2012-10-12 02:35:18 +08:00
|
|
|
static int cmll_t4_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
|
|
const unsigned char *in, size_t len);
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
# define cmll_t4_ecb_cipher camellia_ecb_cipher
|
2012-10-12 02:35:18 +08:00
|
|
|
static int cmll_t4_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
|
|
const unsigned char *in, size_t len);
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
# define cmll_t4_ofb_cipher camellia_ofb_cipher
|
2012-10-12 02:35:18 +08:00
|
|
|
static int cmll_t4_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
|
|
const unsigned char *in, size_t len);
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
# define cmll_t4_cfb_cipher camellia_cfb_cipher
|
2012-10-12 02:35:18 +08:00
|
|
|
static int cmll_t4_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
|
|
const unsigned char *in, size_t len);
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
# define cmll_t4_cfb8_cipher camellia_cfb8_cipher
|
2012-10-12 02:35:18 +08:00
|
|
|
static int cmll_t4_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
|
|
const unsigned char *in, size_t len);
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
# define cmll_t4_cfb1_cipher camellia_cfb1_cipher
|
2012-10-12 02:35:18 +08:00
|
|
|
static int cmll_t4_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
|
|
const unsigned char *in, size_t len);
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
# define cmll_t4_ctr_cipher camellia_ctr_cipher
|
2012-10-12 02:35:18 +08:00
|
|
|
static int cmll_t4_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
|
|
const unsigned char *in, size_t len);
|
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
# define BLOCK_CIPHER_generic(nid,keylen,blocksize,ivlen,nmode,mode,MODE,flags) \
|
2012-10-12 02:35:18 +08:00
|
|
|
static const EVP_CIPHER cmll_t4_##keylen##_##mode = { \
|
|
|
|
nid##_##keylen##_##nmode,blocksize,keylen/8,ivlen, \
|
|
|
|
flags|EVP_CIPH_##MODE##_MODE, \
|
Add "origin" field to EVP_CIPHER, EVP_MD
Add a "where did this EVP_{CIPHER,MD} come from" flag: global, via fetch,
or via EVP_{CIPHER,MD}_meth_new. Update EVP_{CIPHER,MD}_free to handle all
three origins. The flag is deliberately right before some function pointers,
so that compile-time failures (int/pointer) will occur, as opposed to
taking a bit in the existing "flags" field. The "global variable" flag
is non-zero, so the default case of using OPENSSL_zalloc (for provider
ciphers), will do the right thing. Ref-counting is a no-op for
Make up_ref no-op for global MD and CIPHER objects
Deprecate EVP_MD_CTX_md(). Added EVP_MD_CTX_get0_md() (same semantics as
the deprecated function) and EVP_MD_CTX_get1_md(). Likewise, deprecate
EVP_CIPHER_CTX_cipher() in favor of EVP_CIPHER_CTX_get0_cipher(), and add
EVP_CIPHER_CTX_get1_CIPHER().
Refactor EVP_MD_free() and EVP_MD_meth_free() to call new common
evp_md_free_int() function.
Refactor EVP_CIPHER_free() and EVP_CIPHER_meth_free() to call new common
evp_cipher_free_int() function.
Also change some flags tests to explicit test == or != zero. E.g.,
if (flags & x) --> if ((flags & x) != 0)
if (!(flags & x)) --> if ((flags & x) == 0)
Only done for those lines where "get0_cipher" calls were made.
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14193)
2021-02-17 06:51:56 +08:00
|
|
|
EVP_ORIG_GLOBAL, \
|
2012-10-12 02:35:18 +08:00
|
|
|
cmll_t4_init_key, \
|
|
|
|
cmll_t4_##mode##_cipher, \
|
|
|
|
NULL, \
|
|
|
|
sizeof(EVP_CAMELLIA_KEY), \
|
|
|
|
NULL,NULL,NULL,NULL }; \
|
|
|
|
static const EVP_CIPHER camellia_##keylen##_##mode = { \
|
|
|
|
nid##_##keylen##_##nmode,blocksize, \
|
|
|
|
keylen/8,ivlen, \
|
|
|
|
flags|EVP_CIPH_##MODE##_MODE, \
|
Add "origin" field to EVP_CIPHER, EVP_MD
Add a "where did this EVP_{CIPHER,MD} come from" flag: global, via fetch,
or via EVP_{CIPHER,MD}_meth_new. Update EVP_{CIPHER,MD}_free to handle all
three origins. The flag is deliberately right before some function pointers,
so that compile-time failures (int/pointer) will occur, as opposed to
taking a bit in the existing "flags" field. The "global variable" flag
is non-zero, so the default case of using OPENSSL_zalloc (for provider
ciphers), will do the right thing. Ref-counting is a no-op for
Make up_ref no-op for global MD and CIPHER objects
Deprecate EVP_MD_CTX_md(). Added EVP_MD_CTX_get0_md() (same semantics as
the deprecated function) and EVP_MD_CTX_get1_md(). Likewise, deprecate
EVP_CIPHER_CTX_cipher() in favor of EVP_CIPHER_CTX_get0_cipher(), and add
EVP_CIPHER_CTX_get1_CIPHER().
Refactor EVP_MD_free() and EVP_MD_meth_free() to call new common
evp_md_free_int() function.
Refactor EVP_CIPHER_free() and EVP_CIPHER_meth_free() to call new common
evp_cipher_free_int() function.
Also change some flags tests to explicit test == or != zero. E.g.,
if (flags & x) --> if ((flags & x) != 0)
if (!(flags & x)) --> if ((flags & x) == 0)
Only done for those lines where "get0_cipher" calls were made.
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14193)
2021-02-17 06:51:56 +08:00
|
|
|
EVP_ORIG_GLOBAL, \
|
2012-10-12 02:35:18 +08:00
|
|
|
camellia_init_key, \
|
|
|
|
camellia_##mode##_cipher, \
|
|
|
|
NULL, \
|
|
|
|
sizeof(EVP_CAMELLIA_KEY), \
|
|
|
|
NULL,NULL,NULL,NULL }; \
|
|
|
|
const EVP_CIPHER *EVP_camellia_##keylen##_##mode(void) \
|
|
|
|
{ return SPARC_CMLL_CAPABLE?&cmll_t4_##keylen##_##mode:&camellia_##keylen##_##mode; }
|
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
#else
|
2012-10-12 02:35:18 +08:00
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
# define BLOCK_CIPHER_generic(nid,keylen,blocksize,ivlen,nmode,mode,MODE,flags) \
|
2012-10-12 02:35:18 +08:00
|
|
|
static const EVP_CIPHER camellia_##keylen##_##mode = { \
|
|
|
|
nid##_##keylen##_##nmode,blocksize,keylen/8,ivlen, \
|
|
|
|
flags|EVP_CIPH_##MODE##_MODE, \
|
Add "origin" field to EVP_CIPHER, EVP_MD
Add a "where did this EVP_{CIPHER,MD} come from" flag: global, via fetch,
or via EVP_{CIPHER,MD}_meth_new. Update EVP_{CIPHER,MD}_free to handle all
three origins. The flag is deliberately right before some function pointers,
so that compile-time failures (int/pointer) will occur, as opposed to
taking a bit in the existing "flags" field. The "global variable" flag
is non-zero, so the default case of using OPENSSL_zalloc (for provider
ciphers), will do the right thing. Ref-counting is a no-op for
Make up_ref no-op for global MD and CIPHER objects
Deprecate EVP_MD_CTX_md(). Added EVP_MD_CTX_get0_md() (same semantics as
the deprecated function) and EVP_MD_CTX_get1_md(). Likewise, deprecate
EVP_CIPHER_CTX_cipher() in favor of EVP_CIPHER_CTX_get0_cipher(), and add
EVP_CIPHER_CTX_get1_CIPHER().
Refactor EVP_MD_free() and EVP_MD_meth_free() to call new common
evp_md_free_int() function.
Refactor EVP_CIPHER_free() and EVP_CIPHER_meth_free() to call new common
evp_cipher_free_int() function.
Also change some flags tests to explicit test == or != zero. E.g.,
if (flags & x) --> if ((flags & x) != 0)
if (!(flags & x)) --> if ((flags & x) == 0)
Only done for those lines where "get0_cipher" calls were made.
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14193)
2021-02-17 06:51:56 +08:00
|
|
|
EVP_ORIG_GLOBAL, \
|
2012-10-12 02:35:18 +08:00
|
|
|
camellia_init_key, \
|
|
|
|
camellia_##mode##_cipher, \
|
|
|
|
NULL, \
|
|
|
|
sizeof(EVP_CAMELLIA_KEY), \
|
|
|
|
NULL,NULL,NULL,NULL }; \
|
|
|
|
const EVP_CIPHER *EVP_camellia_##keylen##_##mode(void) \
|
|
|
|
{ return &camellia_##keylen##_##mode; }
|
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
#endif
|
2006-06-11 09:09:07 +08:00
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
#define BLOCK_CIPHER_generic_pack(nid,keylen,flags) \
|
2012-10-12 02:35:18 +08:00
|
|
|
BLOCK_CIPHER_generic(nid,keylen,16,16,cbc,cbc,CBC,flags|EVP_CIPH_FLAG_DEFAULT_ASN1) \
|
|
|
|
BLOCK_CIPHER_generic(nid,keylen,16,0,ecb,ecb,ECB,flags|EVP_CIPH_FLAG_DEFAULT_ASN1) \
|
|
|
|
BLOCK_CIPHER_generic(nid,keylen,1,16,ofb128,ofb,OFB,flags|EVP_CIPH_FLAG_DEFAULT_ASN1) \
|
|
|
|
BLOCK_CIPHER_generic(nid,keylen,1,16,cfb128,cfb,CFB,flags|EVP_CIPH_FLAG_DEFAULT_ASN1) \
|
|
|
|
BLOCK_CIPHER_generic(nid,keylen,1,16,cfb1,cfb1,CFB,flags) \
|
2015-02-12 03:30:13 +08:00
|
|
|
BLOCK_CIPHER_generic(nid,keylen,1,16,cfb8,cfb8,CFB,flags) \
|
|
|
|
BLOCK_CIPHER_generic(nid, keylen, 1, 16, ctr, ctr, CTR, flags)
|
|
|
|
|
2006-06-11 09:09:07 +08:00
|
|
|
/* The subkey for Camellia is generated. */
|
|
|
|
static int camellia_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
2012-10-12 02:35:18 +08:00
|
|
|
const unsigned char *iv, int enc)
|
|
|
|
{
|
|
|
|
int ret, mode;
|
2021-10-26 15:16:18 +08:00
|
|
|
EVP_CAMELLIA_KEY *dat = EVP_C_DATA(EVP_CAMELLIA_KEY, ctx);
|
2015-01-22 11:40:55 +08:00
|
|
|
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
ret = Camellia_set_key(key, EVP_CIPHER_CTX_get_key_length(ctx) * 8,
|
|
|
|
&dat->ks);
|
2006-06-11 09:09:07 +08:00
|
|
|
if (ret < 0) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_EVP, EVP_R_CAMELLIA_KEY_SETUP_FAILED);
|
2006-06-11 09:09:07 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
mode = EVP_CIPHER_CTX_get_mode(ctx);
|
2012-10-12 02:35:18 +08:00
|
|
|
if ((mode == EVP_CIPH_ECB_MODE || mode == EVP_CIPH_CBC_MODE)
|
2015-01-22 11:40:55 +08:00
|
|
|
&& !enc) {
|
2012-10-12 02:35:18 +08:00
|
|
|
dat->block = (block128_f) Camellia_decrypt;
|
|
|
|
dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
|
|
|
|
(cbc128_f) Camellia_cbc_encrypt : NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
} else {
|
2012-10-12 02:35:18 +08:00
|
|
|
dat->block = (block128_f) Camellia_encrypt;
|
|
|
|
dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ?
|
|
|
|
(cbc128_f) Camellia_cbc_encrypt : NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
|
2006-06-11 09:09:07 +08:00
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2012-10-12 02:35:18 +08:00
|
|
|
|
|
|
|
static int camellia_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
|
|
const unsigned char *in, size_t len)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2021-10-26 15:16:18 +08:00
|
|
|
EVP_CAMELLIA_KEY *dat = EVP_C_DATA(EVP_CAMELLIA_KEY, ctx);
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2012-10-12 02:35:18 +08:00
|
|
|
if (dat->stream.cbc)
|
2020-07-03 05:12:33 +08:00
|
|
|
(*dat->stream.cbc) (in, out, len, &dat->ks, ctx->iv,
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
EVP_CIPHER_CTX_is_encrypting(ctx));
|
|
|
|
else if (EVP_CIPHER_CTX_is_encrypting(ctx))
|
2020-07-03 05:12:33 +08:00
|
|
|
CRYPTO_cbc128_encrypt(in, out, len, &dat->ks, ctx->iv, dat->block);
|
2012-10-12 02:35:18 +08:00
|
|
|
else
|
2020-07-03 05:12:33 +08:00
|
|
|
CRYPTO_cbc128_decrypt(in, out, len, &dat->ks, ctx->iv, dat->block);
|
2012-10-12 02:35:18 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int camellia_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
|
|
const unsigned char *in, size_t len)
|
|
|
|
{
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
size_t bl = EVP_CIPHER_CTX_get_block_size(ctx);
|
2012-10-12 02:35:18 +08:00
|
|
|
size_t i;
|
2021-10-26 15:16:18 +08:00
|
|
|
EVP_CAMELLIA_KEY *dat = EVP_C_DATA(EVP_CAMELLIA_KEY, ctx);
|
2012-10-12 02:35:18 +08:00
|
|
|
|
|
|
|
if (len < bl)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
for (i = 0, len -= bl; i <= len; i += bl)
|
|
|
|
(*dat->block) (in + i, out + i, &dat->ks);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int camellia_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
|
|
const unsigned char *in, size_t len)
|
|
|
|
{
|
2021-10-26 15:16:18 +08:00
|
|
|
EVP_CAMELLIA_KEY *dat = EVP_C_DATA(EVP_CAMELLIA_KEY, ctx);
|
2012-10-12 02:35:18 +08:00
|
|
|
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
int num = EVP_CIPHER_CTX_get_num(ctx);
|
2020-07-03 05:12:33 +08:00
|
|
|
CRYPTO_ofb128_encrypt(in, out, len, &dat->ks, ctx->iv, &num, dat->block);
|
2015-12-19 00:01:28 +08:00
|
|
|
EVP_CIPHER_CTX_set_num(ctx, num);
|
2012-10-12 02:35:18 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int camellia_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
|
|
const unsigned char *in, size_t len)
|
|
|
|
{
|
2021-10-26 15:16:18 +08:00
|
|
|
EVP_CAMELLIA_KEY *dat = EVP_C_DATA(EVP_CAMELLIA_KEY, ctx);
|
2012-10-12 02:35:18 +08:00
|
|
|
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
int num = EVP_CIPHER_CTX_get_num(ctx);
|
2020-07-03 05:12:33 +08:00
|
|
|
CRYPTO_cfb128_encrypt(in, out, len, &dat->ks, ctx->iv, &num,
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
EVP_CIPHER_CTX_is_encrypting(ctx), dat->block);
|
2015-12-19 00:01:28 +08:00
|
|
|
EVP_CIPHER_CTX_set_num(ctx, num);
|
2012-10-12 02:35:18 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int camellia_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
|
|
const unsigned char *in, size_t len)
|
|
|
|
{
|
2021-10-26 15:16:18 +08:00
|
|
|
EVP_CAMELLIA_KEY *dat = EVP_C_DATA(EVP_CAMELLIA_KEY, ctx);
|
2012-10-12 02:35:18 +08:00
|
|
|
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
int num = EVP_CIPHER_CTX_get_num(ctx);
|
2020-07-03 05:12:33 +08:00
|
|
|
CRYPTO_cfb128_8_encrypt(in, out, len, &dat->ks, ctx->iv, &num,
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
EVP_CIPHER_CTX_is_encrypting(ctx), dat->block);
|
2015-12-19 00:01:28 +08:00
|
|
|
EVP_CIPHER_CTX_set_num(ctx, num);
|
2012-10-12 02:35:18 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int camellia_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
|
|
const unsigned char *in, size_t len)
|
|
|
|
{
|
2021-10-26 15:16:18 +08:00
|
|
|
EVP_CAMELLIA_KEY *dat = EVP_C_DATA(EVP_CAMELLIA_KEY, ctx);
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2015-12-19 00:01:28 +08:00
|
|
|
if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS)) {
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
int num = EVP_CIPHER_CTX_get_num(ctx);
|
2020-07-03 05:12:33 +08:00
|
|
|
CRYPTO_cfb128_1_encrypt(in, out, len, &dat->ks, ctx->iv, &num,
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
EVP_CIPHER_CTX_is_encrypting(ctx),
|
|
|
|
dat->block);
|
2015-12-19 00:01:28 +08:00
|
|
|
EVP_CIPHER_CTX_set_num(ctx, num);
|
2012-10-12 02:35:18 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2012-10-12 02:35:18 +08:00
|
|
|
while (len >= MAXBITCHUNK) {
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
int num = EVP_CIPHER_CTX_get_num(ctx);
|
2012-10-12 02:35:18 +08:00
|
|
|
CRYPTO_cfb128_1_encrypt(in, out, MAXBITCHUNK * 8, &dat->ks,
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
ctx->iv, &num,
|
|
|
|
EVP_CIPHER_CTX_is_encrypting(ctx),
|
|
|
|
dat->block);
|
2015-12-19 00:01:28 +08:00
|
|
|
EVP_CIPHER_CTX_set_num(ctx, num);
|
2018-02-21 22:48:02 +08:00
|
|
|
len -= MAXBITCHUNK;
|
|
|
|
out += MAXBITCHUNK;
|
|
|
|
in += MAXBITCHUNK;
|
2012-10-12 02:35:18 +08:00
|
|
|
}
|
2015-12-19 00:01:28 +08:00
|
|
|
if (len) {
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
int num = EVP_CIPHER_CTX_get_num(ctx);
|
2012-10-12 02:35:18 +08:00
|
|
|
CRYPTO_cfb128_1_encrypt(in, out, len * 8, &dat->ks,
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
ctx->iv, &num,
|
|
|
|
EVP_CIPHER_CTX_is_encrypting(ctx),
|
|
|
|
dat->block);
|
2015-12-19 00:01:28 +08:00
|
|
|
EVP_CIPHER_CTX_set_num(ctx, num);
|
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2012-10-12 02:35:18 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int camellia_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|
|
|
const unsigned char *in, size_t len)
|
|
|
|
{
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
int snum = EVP_CIPHER_CTX_get_num(ctx);
|
enc: fix coverity 1451499, 1451501, 1451506, 1451507, 1351511, 1451514, 1451517, 1451523, 1451526m 1451528, 1451539, 1451441, 1451549, 1451568 & 1451572: improper use of negative value
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14638)
2021-03-22 10:09:19 +08:00
|
|
|
unsigned int num;
|
2021-10-26 15:16:18 +08:00
|
|
|
EVP_CAMELLIA_KEY *dat = EVP_C_DATA(EVP_CAMELLIA_KEY, ctx);
|
2015-01-22 11:40:55 +08:00
|
|
|
|
enc: fix coverity 1451499, 1451501, 1451506, 1451507, 1351511, 1451514, 1451517, 1451523, 1451526m 1451528, 1451539, 1451441, 1451549, 1451568 & 1451572: improper use of negative value
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14638)
2021-03-22 10:09:19 +08:00
|
|
|
if (snum < 0)
|
|
|
|
return 0;
|
|
|
|
num = snum;
|
2012-10-12 02:35:18 +08:00
|
|
|
if (dat->stream.ctr)
|
2020-07-03 05:12:33 +08:00
|
|
|
CRYPTO_ctr128_encrypt_ctr32(in, out, len, &dat->ks, ctx->iv,
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
EVP_CIPHER_CTX_buf_noconst(ctx),
|
|
|
|
&num,
|
2015-12-19 00:01:28 +08:00
|
|
|
dat->stream.ctr);
|
2012-10-12 02:35:18 +08:00
|
|
|
else
|
2020-07-03 05:12:33 +08:00
|
|
|
CRYPTO_ctr128_encrypt(in, out, len, &dat->ks, ctx->iv,
|
2015-12-19 00:01:28 +08:00
|
|
|
EVP_CIPHER_CTX_buf_noconst(ctx), &num,
|
|
|
|
dat->block);
|
|
|
|
EVP_CIPHER_CTX_set_num(ctx, num);
|
2012-10-12 02:35:18 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-11-05 17:20:41 +08:00
|
|
|
BLOCK_CIPHER_generic_pack(NID_camellia, 128, 0)
|
|
|
|
BLOCK_CIPHER_generic_pack(NID_camellia, 192, 0)
|
|
|
|
BLOCK_CIPHER_generic_pack(NID_camellia, 256, 0)
|