diff --git a/crypto/cmp/cmp_kem.c b/crypto/cmp/cmp_kem.c index a7ef57be39ddaf..355a5ca81950c1 100644 --- a/crypto/cmp/cmp_kem.c +++ b/crypto/cmp/cmp_kem.c @@ -15,6 +15,21 @@ #include #include +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) @@ -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); @@ -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; }