mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-18 05:42:35 +00:00
aria/camellia/des: guard setkey_dec by CIPHER_ENCRYPT_ONLY
This is a pre-step to remove *setkey_dec_func in cipher_wrap ctx when CIPHER_ENCRYPT_ONLY is enabled. Signed-off-by: Yanray Wang <yanray.wang@arm.com>
This commit is contained in:
parent
a8ac23a758
commit
9141ad1223
@ -110,6 +110,7 @@ int mbedtls_aria_setkey_enc(mbedtls_aria_context *ctx,
|
|||||||
const unsigned char *key,
|
const unsigned char *key,
|
||||||
unsigned int keybits);
|
unsigned int keybits);
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
/**
|
/**
|
||||||
* \brief This function sets the decryption key.
|
* \brief This function sets the decryption key.
|
||||||
*
|
*
|
||||||
@ -128,6 +129,7 @@ int mbedtls_aria_setkey_enc(mbedtls_aria_context *ctx,
|
|||||||
int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
|
int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
|
||||||
const unsigned char *key,
|
const unsigned char *key,
|
||||||
unsigned int keybits);
|
unsigned int keybits);
|
||||||
|
#endif /* !MBEDTLS_CIPHER_ENCRYPT_ONLY */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief This function performs an ARIA single-block encryption or
|
* \brief This function performs an ARIA single-block encryption or
|
||||||
|
@ -93,6 +93,7 @@ int mbedtls_camellia_setkey_enc(mbedtls_camellia_context *ctx,
|
|||||||
const unsigned char *key,
|
const unsigned char *key,
|
||||||
unsigned int keybits);
|
unsigned int keybits);
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
/**
|
/**
|
||||||
* \brief Perform a CAMELLIA key schedule operation for decryption.
|
* \brief Perform a CAMELLIA key schedule operation for decryption.
|
||||||
*
|
*
|
||||||
@ -108,6 +109,7 @@ int mbedtls_camellia_setkey_enc(mbedtls_camellia_context *ctx,
|
|||||||
int mbedtls_camellia_setkey_dec(mbedtls_camellia_context *ctx,
|
int mbedtls_camellia_setkey_dec(mbedtls_camellia_context *ctx,
|
||||||
const unsigned char *key,
|
const unsigned char *key,
|
||||||
unsigned int keybits);
|
unsigned int keybits);
|
||||||
|
#endif /* !MBEDTLS_CIPHER_ENCRYPT_ONLY */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Perform a CAMELLIA-ECB block encryption/decryption operation.
|
* \brief Perform a CAMELLIA-ECB block encryption/decryption operation.
|
||||||
|
@ -182,6 +182,7 @@ int mbedtls_des_key_check_weak(const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
|
|||||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_des_setkey_enc(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
|
int mbedtls_des_setkey_enc(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
/**
|
/**
|
||||||
* \brief DES key schedule (56-bit, decryption)
|
* \brief DES key schedule (56-bit, decryption)
|
||||||
*
|
*
|
||||||
@ -196,6 +197,7 @@ int mbedtls_des_setkey_enc(mbedtls_des_context *ctx, const unsigned char key[MBE
|
|||||||
*/
|
*/
|
||||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
|
int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]);
|
||||||
|
#endif /* !MBEDTLS_CIPHER_ENCRYPT_ONLY */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Triple-DES key schedule (112-bit, encryption)
|
* \brief Triple-DES key schedule (112-bit, encryption)
|
||||||
@ -213,6 +215,7 @@ MBEDTLS_CHECK_RETURN_TYPICAL
|
|||||||
int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx,
|
int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx,
|
||||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
|
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
/**
|
/**
|
||||||
* \brief Triple-DES key schedule (112-bit, decryption)
|
* \brief Triple-DES key schedule (112-bit, decryption)
|
||||||
*
|
*
|
||||||
@ -228,6 +231,7 @@ int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx,
|
|||||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx,
|
int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx,
|
||||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
|
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]);
|
||||||
|
#endif /* !MBEDTLS_CIPHER_ENCRYPT_ONLY */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Triple-DES key schedule (168-bit, encryption)
|
* \brief Triple-DES key schedule (168-bit, encryption)
|
||||||
@ -245,6 +249,7 @@ MBEDTLS_CHECK_RETURN_TYPICAL
|
|||||||
int mbedtls_des3_set3key_enc(mbedtls_des3_context *ctx,
|
int mbedtls_des3_set3key_enc(mbedtls_des3_context *ctx,
|
||||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
|
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
/**
|
/**
|
||||||
* \brief Triple-DES key schedule (168-bit, decryption)
|
* \brief Triple-DES key schedule (168-bit, decryption)
|
||||||
*
|
*
|
||||||
@ -260,6 +265,7 @@ int mbedtls_des3_set3key_enc(mbedtls_des3_context *ctx,
|
|||||||
MBEDTLS_CHECK_RETURN_TYPICAL
|
MBEDTLS_CHECK_RETURN_TYPICAL
|
||||||
int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx,
|
int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx,
|
||||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
|
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]);
|
||||||
|
#endif /* !MBEDTLS_CIPHER_ENCRYPT_ONLY */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief DES-ECB block encryption/decryption
|
* \brief DES-ECB block encryption/decryption
|
||||||
|
@ -425,6 +425,7 @@ int mbedtls_aria_setkey_enc(mbedtls_aria_context *ctx,
|
|||||||
/*
|
/*
|
||||||
* Set decryption key
|
* Set decryption key
|
||||||
*/
|
*/
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
|
int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
|
||||||
const unsigned char *key, unsigned int keybits)
|
const unsigned char *key, unsigned int keybits)
|
||||||
{
|
{
|
||||||
@ -454,6 +455,7 @@ int mbedtls_aria_setkey_dec(mbedtls_aria_context *ctx,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif /* !MBEDTLS_CIPHER_ENCRYPT_ONLY */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Encrypt a block
|
* Encrypt a block
|
||||||
@ -884,12 +886,18 @@ int mbedtls_aria_self_test(int verbose)
|
|||||||
/* test ECB decryption */
|
/* test ECB decryption */
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
mbedtls_printf(" ARIA-ECB-%d (dec): ", 128 + 64 * i);
|
mbedtls_printf(" ARIA-ECB-%d (dec): ", 128 + 64 * i);
|
||||||
|
#if defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
|
mbedtls_printf("skipped\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
mbedtls_aria_setkey_dec(&ctx, aria_test1_ecb_key, 128 + 64 * i);
|
mbedtls_aria_setkey_dec(&ctx, aria_test1_ecb_key, 128 + 64 * i);
|
||||||
mbedtls_aria_crypt_ecb(&ctx, aria_test1_ecb_ct[i], blk);
|
mbedtls_aria_crypt_ecb(&ctx, aria_test1_ecb_ct[i], blk);
|
||||||
ARIA_SELF_TEST_ASSERT(
|
ARIA_SELF_TEST_ASSERT(
|
||||||
memcmp(blk, aria_test1_ecb_pt, MBEDTLS_ARIA_BLOCKSIZE)
|
memcmp(blk, aria_test1_ecb_pt, MBEDTLS_ARIA_BLOCKSIZE)
|
||||||
!= 0);
|
!= 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
mbedtls_printf("\n");
|
mbedtls_printf("\n");
|
||||||
|
@ -411,6 +411,7 @@ int mbedtls_camellia_setkey_enc(mbedtls_camellia_context *ctx,
|
|||||||
/*
|
/*
|
||||||
* Camellia key schedule (decryption)
|
* Camellia key schedule (decryption)
|
||||||
*/
|
*/
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
int mbedtls_camellia_setkey_dec(mbedtls_camellia_context *ctx,
|
int mbedtls_camellia_setkey_dec(mbedtls_camellia_context *ctx,
|
||||||
const unsigned char *key,
|
const unsigned char *key,
|
||||||
unsigned int keybits)
|
unsigned int keybits)
|
||||||
@ -456,6 +457,7 @@ exit:
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif /* !MBEDTLS_CIPHER_ENCRYPT_ONLY */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Camellia-ECB block encryption/decryption
|
* Camellia-ECB block encryption/decryption
|
||||||
@ -900,14 +902,26 @@ int mbedtls_camellia_self_test(int verbose)
|
|||||||
(v == MBEDTLS_CAMELLIA_DECRYPT) ? "dec" : "enc");
|
(v == MBEDTLS_CAMELLIA_DECRYPT) ? "dec" : "enc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
|
if (v == MBEDTLS_CAMELLIA_DECRYPT) {
|
||||||
|
if (verbose != 0) {
|
||||||
|
mbedtls_printf("skipped\n");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
for (i = 0; i < CAMELLIA_TESTS_ECB; i++) {
|
for (i = 0; i < CAMELLIA_TESTS_ECB; i++) {
|
||||||
memcpy(key, camellia_test_ecb_key[u][i], 16 + 8 * u);
|
memcpy(key, camellia_test_ecb_key[u][i], 16 + 8 * u);
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
if (v == MBEDTLS_CAMELLIA_DECRYPT) {
|
if (v == MBEDTLS_CAMELLIA_DECRYPT) {
|
||||||
mbedtls_camellia_setkey_dec(&ctx, key, 128 + u * 64);
|
mbedtls_camellia_setkey_dec(&ctx, key, 128 + u * 64);
|
||||||
memcpy(src, camellia_test_ecb_cipher[u][i], 16);
|
memcpy(src, camellia_test_ecb_cipher[u][i], 16);
|
||||||
memcpy(dst, camellia_test_ecb_plain[i], 16);
|
memcpy(dst, camellia_test_ecb_plain[i], 16);
|
||||||
} else { /* MBEDTLS_CAMELLIA_ENCRYPT */
|
} else
|
||||||
|
#endif
|
||||||
|
{ /* MBEDTLS_CAMELLIA_ENCRYPT */
|
||||||
mbedtls_camellia_setkey_enc(&ctx, key, 128 + u * 64);
|
mbedtls_camellia_setkey_enc(&ctx, key, 128 + u * 64);
|
||||||
memcpy(src, camellia_test_ecb_plain[i], 16);
|
memcpy(src, camellia_test_ecb_plain[i], 16);
|
||||||
memcpy(dst, camellia_test_ecb_cipher[u][i], 16);
|
memcpy(dst, camellia_test_ecb_cipher[u][i], 16);
|
||||||
|
@ -483,6 +483,7 @@ int mbedtls_des_setkey_enc(mbedtls_des_context *ctx, const unsigned char key[MBE
|
|||||||
/*
|
/*
|
||||||
* DES key schedule (56-bit, decryption)
|
* DES key schedule (56-bit, decryption)
|
||||||
*/
|
*/
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE])
|
int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -496,6 +497,7 @@ int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBE
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void des3_set2key(uint32_t esk[96],
|
static void des3_set2key(uint32_t esk[96],
|
||||||
uint32_t dsk[96],
|
uint32_t dsk[96],
|
||||||
@ -538,6 +540,7 @@ int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx,
|
|||||||
/*
|
/*
|
||||||
* Triple-DES key schedule (112-bit, decryption)
|
* Triple-DES key schedule (112-bit, decryption)
|
||||||
*/
|
*/
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx,
|
int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx,
|
||||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2])
|
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2])
|
||||||
{
|
{
|
||||||
@ -548,6 +551,7 @@ int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void des3_set3key(uint32_t esk[96],
|
static void des3_set3key(uint32_t esk[96],
|
||||||
uint32_t dsk[96],
|
uint32_t dsk[96],
|
||||||
@ -588,6 +592,7 @@ int mbedtls_des3_set3key_enc(mbedtls_des3_context *ctx,
|
|||||||
/*
|
/*
|
||||||
* Triple-DES key schedule (168-bit, decryption)
|
* Triple-DES key schedule (168-bit, decryption)
|
||||||
*/
|
*/
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx,
|
int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx,
|
||||||
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3])
|
const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3])
|
||||||
{
|
{
|
||||||
@ -598,6 +603,7 @@ int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DES-ECB block encryption/decryption
|
* DES-ECB block encryption/decryption
|
||||||
@ -869,28 +875,43 @@ int mbedtls_des_self_test(int verbose)
|
|||||||
(v == MBEDTLS_DES_DECRYPT) ? "dec" : "enc");
|
(v == MBEDTLS_DES_DECRYPT) ? "dec" : "enc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
|
if (v == MBEDTLS_DES_DECRYPT) {
|
||||||
|
if (verbose != 0) {
|
||||||
|
mbedtls_printf("skipped\n");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
memcpy(buf, des3_test_buf, 8);
|
memcpy(buf, des3_test_buf, 8);
|
||||||
|
|
||||||
switch (i) {
|
switch (i) {
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
case 0:
|
case 0:
|
||||||
ret = mbedtls_des_setkey_dec(&ctx, des3_test_keys);
|
ret = mbedtls_des_setkey_dec(&ctx, des3_test_keys);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
ret = mbedtls_des_setkey_enc(&ctx, des3_test_keys);
|
ret = mbedtls_des_setkey_enc(&ctx, des3_test_keys);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
case 2:
|
case 2:
|
||||||
ret = mbedtls_des3_set2key_dec(&ctx3, des3_test_keys);
|
ret = mbedtls_des3_set2key_dec(&ctx3, des3_test_keys);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
ret = mbedtls_des3_set2key_enc(&ctx3, des3_test_keys);
|
ret = mbedtls_des3_set2key_enc(&ctx3, des3_test_keys);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_CIPHER_ENCRYPT_ONLY)
|
||||||
case 4:
|
case 4:
|
||||||
ret = mbedtls_des3_set3key_dec(&ctx3, des3_test_keys);
|
ret = mbedtls_des3_set3key_dec(&ctx3, des3_test_keys);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
ret = mbedtls_des3_set3key_enc(&ctx3, des3_test_keys);
|
ret = mbedtls_des3_set3key_enc(&ctx3, des3_test_keys);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user