Skip to content

Commit

Permalink
hotplace rev.350 COSE ECDH-ES/SS+AES-KEYWRAP
Browse files Browse the repository at this point in the history
  • Loading branch information
princeb612 committed Oct 21, 2023
1 parent 9658864 commit 5aedcb7
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 99 deletions.
64 changes: 0 additions & 64 deletions .github/workflows/codacy.yml

This file was deleted.

20 changes: 10 additions & 10 deletions sdk/crypto/basic/crypto_advisor_hint_cose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const hint_cose_algorithm_t hint_cose_algorithms[] = {
cose_group_t::cose_group_ecdhes_aeskw,
{
"sha256",
32,
16,
},
{
"aes-128-wrap",
Expand All @@ -214,8 +214,8 @@ const hint_cose_algorithm_t hint_cose_algorithms[] = {
crypto_kty_t::kty_ec,
cose_group_t::cose_group_ecdhes_aeskw,
{
"sha384",
48,
"sha256",
24,
},
{
"aes-192-wrap",
Expand All @@ -226,8 +226,8 @@ const hint_cose_algorithm_t hint_cose_algorithms[] = {
crypto_kty_t::kty_ec,
cose_group_t::cose_group_ecdhes_aeskw,
{
"sha512",
64,
"sha256",
32,
},
{
"aes-256-wrap",
Expand All @@ -239,7 +239,7 @@ const hint_cose_algorithm_t hint_cose_algorithms[] = {
cose_group_t::cose_group_ecdhss_aeskw,
{
"sha256",
32,
16,
},
{
"aes-128-wrap",
Expand All @@ -251,8 +251,8 @@ const hint_cose_algorithm_t hint_cose_algorithms[] = {
crypto_kty_t::kty_ec,
cose_group_t::cose_group_ecdhss_aeskw,
{
"sha384",
48,
"sha256",
24,
},
{
"aes-192-wrap",
Expand All @@ -264,8 +264,8 @@ const hint_cose_algorithm_t hint_cose_algorithms[] = {
crypto_kty_t::kty_ec,
cose_group_t::cose_group_ecdhss_aeskw,
{
"sha512",
64,
"sha256",
32,
},
{
"aes-256-wrap",
Expand Down
6 changes: 3 additions & 3 deletions sdk/crypto/basic/openssl_ecdh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ return_t dh_key_agreement(EVP_PKEY* pkey, EVP_PKEY* peer, binary_t& secret) {
ret_test = EVP_PKEY_derive_set_peer(pkey_context, pkey_peer);
if (1 > ret_test) {
ret = errorcode_t::internal_error;
__leave2;
__leave2_trace_openssl(ret);
}
ret_test = EVP_PKEY_derive(pkey_context, nullptr, &size_secret);
if (1 > ret_test) {
ret = errorcode_t::internal_error;
__leave2;
__leave2_trace_openssl(ret);
}
secret.resize(size_secret);
ret_test = EVP_PKEY_derive(pkey_context, &secret[0], &size_secret);
if (1 > ret_test) {
ret = errorcode_t::internal_error;
__leave2;
__leave2_trace_openssl(ret);
}
}
__finally2 { EVP_PKEY_free(pkey_peer); }
Expand Down
13 changes: 13 additions & 0 deletions sdk/crypto/cose/cbor_object_encryption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,9 @@ return_t cbor_object_encryption::decrypt(cose_context_t* handle, crypto_key* key
// reversing "AAD_hex", "CEK_hex", "Context_hex", "KEK_hex" from https://github.com/cose-wg/Examples

if (cose_group_t::cose_group_aeskw == group) {
#if defined DEBUG
handle->debug_flag |= cose_debug_aeskw;
#endif
} else if (cose_group_t::cose_group_direct == group) {
// RFC 8152 12.1. Direct Encryption
cek = secret;
Expand Down Expand Up @@ -632,6 +635,16 @@ return_t cbor_object_encryption::decrypt(cose_context_t* handle, crypto_key* key
#if defined DEBUG
dump_memory(authenticated_data, &bs);
printf("AAD\n%s\n%s\n", bs.c_str(), base16_encode(authenticated_data).c_str());
dump_memory(context, &bs);
printf("Context\n%s\n%s\n", bs.c_str(), base16_encode(context).c_str());
if (secret.size()) {
dump_memory(secret, &bs);
printf("secret\n%s\n%s\n", bs.c_str(), base16_encode(secret).c_str());
}
if (iv.size()) {
dump_memory(iv, &bs);
printf("IV\n%s\n%s\n", bs.c_str(), base16_encode(iv).c_str());
}
if (kek.size()) {
dump_memory(kek, &bs);
printf("KEK\n%s\n%s\n", bs.c_str(), base16_encode(kek).c_str());
Expand Down
1 change: 1 addition & 0 deletions sdk/crypto/cose/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum code_debug_flag_t {
cose_debug_partial_iv = (1 << 1),
cose_debug_aescmac = (1 << 2),
cose_debug_chacha20_poly1305 = (1 << 3),
cose_debug_aeskw = (1 << 4),
};

typedef std::map<int, variant_t> cose_variantmap_t;
Expand Down
Loading

0 comments on commit 5aedcb7

Please sign in to comment.