Skip to content

Commit

Permalink
selftests/tls: add SM4 GCM/CCM to tls selftests
Browse files Browse the repository at this point in the history
Add new cipher as a variant of standard tls selftests.

Signed-off-by: Tianjia Zhang <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
uudiin authored and kuba-moo committed Oct 8, 2021
1 parent 6ed3f61 commit e506342
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions tools/testing/selftests/net/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct tls_crypto_info_keys {
union {
struct tls12_crypto_info_aes_gcm_128 aes128;
struct tls12_crypto_info_chacha20_poly1305 chacha20;
struct tls12_crypto_info_sm4_gcm sm4gcm;
struct tls12_crypto_info_sm4_ccm sm4ccm;
};
size_t len;
};
Expand All @@ -49,6 +51,16 @@ static void tls_crypto_info_init(uint16_t tls_version, uint16_t cipher_type,
tls12->aes128.info.version = tls_version;
tls12->aes128.info.cipher_type = cipher_type;
break;
case TLS_CIPHER_SM4_GCM:
tls12->len = sizeof(struct tls12_crypto_info_sm4_gcm);
tls12->sm4gcm.info.version = tls_version;
tls12->sm4gcm.info.cipher_type = cipher_type;
break;
case TLS_CIPHER_SM4_CCM:
tls12->len = sizeof(struct tls12_crypto_info_sm4_ccm);
tls12->sm4ccm.info.version = tls_version;
tls12->sm4ccm.info.cipher_type = cipher_type;
break;
default:
break;
}
Expand Down Expand Up @@ -148,13 +160,13 @@ FIXTURE_VARIANT(tls)
uint16_t cipher_type;
};

FIXTURE_VARIANT_ADD(tls, 12_gcm)
FIXTURE_VARIANT_ADD(tls, 12_aes_gcm)
{
.tls_version = TLS_1_2_VERSION,
.cipher_type = TLS_CIPHER_AES_GCM_128,
};

FIXTURE_VARIANT_ADD(tls, 13_gcm)
FIXTURE_VARIANT_ADD(tls, 13_aes_gcm)
{
.tls_version = TLS_1_3_VERSION,
.cipher_type = TLS_CIPHER_AES_GCM_128,
Expand All @@ -172,6 +184,18 @@ FIXTURE_VARIANT_ADD(tls, 13_chacha)
.cipher_type = TLS_CIPHER_CHACHA20_POLY1305,
};

FIXTURE_VARIANT_ADD(tls, 13_sm4_gcm)
{
.tls_version = TLS_1_3_VERSION,
.cipher_type = TLS_CIPHER_SM4_GCM,
};

FIXTURE_VARIANT_ADD(tls, 13_sm4_ccm)
{
.tls_version = TLS_1_3_VERSION,
.cipher_type = TLS_CIPHER_SM4_CCM,
};

FIXTURE_SETUP(tls)
{
struct tls_crypto_info_keys tls12;
Expand Down

0 comments on commit e506342

Please sign in to comment.