Skip to content

Commit

Permalink
cmp_kem.c: add debug buffer print message
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeev-0 committed Aug 16, 2023
1 parent 912d800 commit 1e2d8b9
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions crypto/cmp/cmp_kem.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
#include <openssl/core_names.h>
#include <openssl/cmp_util.h>

static void print_buf(const char *title, const unsigned char *buf,
size_t buf_len)
{
size_t i = 0;

if(buf == NULL || title == NULL)
return;

fprintf(stdout, "%s , len %ld\n", title, buf_len);
for (i = 0; i < buf_len; ++i)
fprintf(stdout, "%02X%s", buf[i],
(i + 1) % 16 == 0 ? "\r\n" : " ");

}

#define KEMCMP_STATICSTRING "CMP-KEM"
int ossl_cmp_kem_KemOtherInfo_new(OSSL_CMP_CTX *ctx,
unsigned char **out, int *len)
Expand Down Expand Up @@ -305,11 +320,11 @@ static int performKemDecapsulation(OSSL_CMP_CTX *ctx, EVP_PKEY *pkey,
goto err;
}
OPENSSL_clear_free(sec, sec_len);

} else {
*secret_len = sec_len;
*secret = sec;
}
print_buf("secret", *secret, *secret_len);
ret = 1;
err:
EVP_PKEY_CTX_free(kem_decaps_ctx);
Expand Down Expand Up @@ -369,10 +384,12 @@ int ossl_cmp_kem_derivessk(OSSL_CMP_CTX *ctx,
if (!ossl_cmp_kem_KemOtherInfo_new(ctx, &info, &info_len)) {
return 0;
}

print_buf("secret", secret, secret_len);
print_buf("\ninfo", info, info_len);
derive_ssk_HKDF(ctx, secret, secret_len,
salt, sizeof(salt), info, info_len,
out, len);
print_buf("\nssk", *out, *len);
return 1;
}

Expand Down

0 comments on commit 1e2d8b9

Please sign in to comment.