1

i make similar func with test2 of Verify RSA signature in c++ using openssl that executes RSA verification. But i have C2027 compile error.

C2027 found at rsa->n = n; and rsa->e = e;. C2027 generally happen when include file is not enough.

my include file is

#include <openssl/sha.h>
#include <openssl/aes.h>
#include <openssl/cmac.h>
#include <openssl/rsa.h>
#include <openssl/evp.h>

and AES Encrypt/Decrypt, CMAC Generation/Verification, SHA256 is working fine.

n is public key, e is exponent, Msg is message, and S is Signature in following func.


int do_rsa_pkcs_1_v1_5_2048_SHA256_test_vector(){
    int ret = 0;

    unsigned char n[256] = { 0xe0, 0xb1, 0x4b, 0x99, 0xcd, 0x61, 0xcd, 0x3d, 0xb9, 0xc2, 0x07, 0x66, 0x68, 0x84, 0x13, 0x24, 0xfa, 0x31, 0x74, 0xf3, 0x3c, 0xe6, 0x6f, 0xfd, 0x51, 0x43, 0x94, 0xd3, 0x41, 0x78, 0xd2, 0x9a, 0x49, 0x49, 0x32, 0x76, 0xb6, 0x77, 0x72, 0x33, 0xe7, 0xd4, 0x6a, 0x3e, 0x68, 0xbc, 0x7c, 0xa7, 0xe8, 0x99, 0xe9, 0x01, 0xd5, 0x4f, 0x6d, 0xee, 0x07, 0x49, 0xc3, 0xe4, 0x8d, 0xdf, 0x68, 0x68, 0x58, 0x67, 0xee, 0x2a, 0xe6, 0x6d, 0xf8, 0x8e, 0xb5, 0x63, 0xf6, 0xdb, 0x13, 0x7a, 0x9f, 0x6b, 0x17, 0x5a, 0x11, 0x2e, 0x0e, 0xda, 0x83, 0x68, 0xe8, 0x8e, 0x45, 0xef, 0xe1, 0xce, 0x14, 0xbc, 0x60, 0x16, 0xd5, 0x26, 0x39, 0x62, 0x70, 0x66, 0xaf, 0x18, 0x72, 0xc7, 0x2f, 0x60, 0xb9, 0x16, 0x1c, 0x1d, 0x23, 0x7e, 0xeb, 0x34, 0xb0, 0xf8, 0x41, 0xb3, 0xf0, 0x89, 0x6f, 0x9f, 0xe0, 0xe1, 0x6b, 0x0f, 0x74, 0x35, 0x2d, 0x10, 0x12, 0x92, 0xcc, 0x46, 0x4a, 0x7e, 0x78, 0x61, 0xbb, 0xeb, 0x86, 0xf6, 0xdf, 0x61, 0x51, 0xcb, 0x26, 0x54, 0x17, 0xc6, 0x6c, 0x56, 0x5e, 0xd8, 0x97, 0x4b, 0xd8, 0xfc, 0x98, 0x4d, 0x5d, 0xdf, 0xd4, 0xeb, 0x91, 0xa3, 0xd5, 0x23, 0x4c, 0xe1, 0xb5, 0x46, 0x7f, 0x3a, 0xde, 0x37, 0x5f, 0x80, 0x2e, 0xc0, 0x72, 0x93, 0xf1, 0x23, 0x6e, 0xfa, 0x30, 0x68, 0xbc, 0x91, 0xb1, 0x58, 0x55, 0x1c, 0x87, 0x5c, 0x5d, 0xc0, 0xa9, 0xd6, 0xfa, 0x32, 0x1b, 0xf9, 0x42, 0x1f, 0x08, 0xde, 0xac, 0x91, 0x0e, 0x35, 0xc1, 0xc2, 0x85, 0x49, 0xee, 0x8e, 0xed, 0x83, 0x30, 0xcf, 0x70, 0x59, 0x5f, 0xf7, 0x0b, 0x94, 0xb4, 0x99, 0x07, 0xe2, 0x76, 0x98, 0xa9, 0xd9, 0x11, 0xf7, 0xac, 0x07, 0x06, 0xaf, 0xcb, 0x1a, 0x4a, 0x39, 0xfe, 0xb3, 0x8b, 0x0a, 0x80, 0x49 };
    unsigned char e[256] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01 };
    unsigned char Msg[128] = { 0x65, 0x04, 0x92, 0x1a, 0x97, 0xcd, 0x57, 0xaa, 0x8f, 0x38, 0x63, 0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xd6, 0xd6, 0x25, 0x4c, 0x8c, 0xdb, 0x1d, 0x22, 0x7d };

    RSA* rsa = RSA_new();

    rsa->n = n;
    rsa->e = e;

    ret = RSA_verify(RSA_PKCS1_PADDING, Msg, sizeof(Msg), S, sizeof(S), rsa);

    return ret;

    }
}

I am using VS2019, Win32Openssl from https://slproweb.com/products/Win32OpenSSL.html and configure VS project according to How to use OpenSSL with Visual Studio.

Does anybody know which include file should be added? Otherwise, how could i modify c source?


The Build error is

1>------ Rebuild All started: Project: test_vector_app, Configuration: Debug Win32 ------
1>test_vector_app.cpp
1>C:\test_vector_app\test_vector_app.cpp(378,8): error C2027: use of undefined type 'rsa_st'
1>C:\Program Files (x86)\OpenSSL-Win32\include\openssl\evp.h(1018): message : see declaration of 'rsa_st'
1>C:\test_vector_app\test_vector_app.cpp(379,8): error C2027: use of undefined type 'rsa_st'
1>C:\Program Files (x86)\OpenSSL-Win32\include\openssl\evp.h(1018): message : see declaration of 'rsa_st'
1>Done building project "test_vector_app.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Soramame
  • 19
  • 5
  • It would be helpful to include the text of the error message. – TonyK Jun 23 '20 at 17:26
  • Thanks @TonyK, I added Build Error Message. – Soramame Jun 23 '20 at 17:55
  • Well then, you just have to find out where `rsa_st` is defined. – TonyK Jun 23 '20 at 18:11
  • I know nothing about openssl, but I found [this interesting page](https://github.com/openssl/openssl/issues/1491) which bears on your problem. It seems you shouldn't be calling `RSA_new` at all. – TonyK Jun 23 '20 at 18:15
  • Thanks @TonyK, next i will try RSA_set0_key(), but this does not seems good solution for my current problem. So, i will move to EVP function. Thanks again. – Soramame Jun 24 '20 at 11:45

1 Answers1

0

Thanks for @TonyK, i think i could correctly modify my code,

rsa->n = n; and rsa->e = e; is modified to

BIGNUM* nn = BN_bin2bn(n, sizeof(n), NULL);
BIGNUM* ee = BN_bin2bn(e, sizeof(e), NULL);
int ret = RSA_set0_key(rsa, nn, ee, NULL);

But there are more problem for my code so i will make more effort.

Soramame
  • 19
  • 5