Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring if (!pkey) in 'soter_sign_ecdsa.c' for OpenSSL/BoringSSL #315

Merged
merged 10 commits into from
May 11, 2018
8 changes: 6 additions & 2 deletions src/soter/boringssl/soter_sign_ecdsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ soter_status_t soter_sign_update_ecdsa_none_pkcs8(soter_sign_ctx_t* ctx, const v
soter_status_t soter_sign_final_ecdsa_none_pkcs8(soter_sign_ctx_t* ctx, void* signature, size_t *signature_length)
{
EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx->pkey_ctx);
if (!pkey && EVP_PKEY_type(pkey->type)!=EVP_PKEY_EC){
if (!pkey) {
return SOTER_INVALID_PARAMETER;
} /* TODO: need review */
}
if (EVP_PKEY_type(pkey->type)!=EVP_PKEY_EC) {
return SOTER_INVALID_PARAMETER;
}
/* TODO: need review */
if(!signature || (*signature_length)<(size_t)EVP_PKEY_size(pkey)){
(*signature_length)=(size_t)EVP_PKEY_size(pkey);
return SOTER_BUFFER_TOO_SMALL;
Expand Down
5 changes: 4 additions & 1 deletion src/soter/openssl/soter_sign_ecdsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ soter_status_t soter_sign_update_ecdsa_none_pkcs8(soter_sign_ctx_t* ctx, const v
soter_status_t soter_sign_final_ecdsa_none_pkcs8(soter_sign_ctx_t* ctx, void* signature, size_t *signature_length)
{
EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(ctx->pkey_ctx);
if (!pkey && EVP_PKEY_base_id(pkey)!=EVP_PKEY_EC){
if (!pkey) {
return SOTER_INVALID_PARAMETER;
}
if (EVP_PKEY_base_id(pkey)!=EVP_PKEY_EC){
return SOTER_INVALID_PARAMETER;
} /* TODO: need review */
soter_status_t res = SOTER_SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion tests/soter/soter_sign_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static void soter_sign_api_test()
soter_sign_destroy(sign_ctx);
return;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space :|

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! fixed

testsuite_fail_unless(SOTER_INVALID_PARAMETER == soter_sign_final(NULL, signature, &signature_length), "soter_sign_final: invalid context");
testsuite_fail_unless(SOTER_BUFFER_TOO_SMALL == soter_sign_final(sign_ctx, NULL, &signature_length), "soter_sign_final: get output size (NULL out buffer)");
signature_length--;
Expand Down