I configured and built openssl 3.0.15 on Windows, and it works fine. I have the static libraries and the shared too. When I tried to link my application to one of these I noticed that it works with the static lib but not with the dll. It seems like the exported symbols are different. Is it intentional? Am I missing something?
I created a dummy application:
#include <stdio.h>
#include <crypto/chacha.h>
int main() {
unsigned char key[32] = {0};
unsigned char nonce[12] = {0};
unsigned char in[64] = {0};
unsigned char out[64] = {0};
// Initialize the key and nonce with some values
for (int i = 0; i < 32; i++) key[i] = i;
for (int i = 0; i < 12; i++) nonce[i] = i;
// Encrypt the input data
ChaCha20_ctr32(out, in, sizeof(in), (const unsigned int *)key, (const unsigned int *)nonce);
// Print the encrypted output
printf("Encrypted output:\n");
for (int i = 0; i < sizeof(out); i++) {
printf("%02x", out[i]);
if ((i + 1) % 16 == 0) printf("\n");
}
return 0;
}
And I tried to build it like this:
cl /I <path-to-openssl>\openssl-openssl-3.0.15\include linktest.c /link /LIBPATH:<path-to-openssl>\openssl-openssl-3.0.15 libcrypto_static.lib
This works.
This does not:
cl /I <path-to-openssl>\openssl-openssl-3.0.15\include linktest.c /link /LIBPATH:<path-to-openssl>\openssl-openssl-3.0.15 libcrypto.lib
Compiler says this:
linktest.obj : error LNK2019: unresolved external symbol ChaCha20_ctr32 referenced in function main
linktest.exe : fatal error LNK1120: 1 unresolved externals
I configured and built openssl 3.0.15 on Windows, and it works fine.
Did you run the nmake install
step? Or are you building your application directly against the headers from the OpenSSL source directory?
You are including the crypto/chacha.h
header file which doesn't get installed via nmake install
as part of the public headers of OpenSSL. That header file is entirely internal to OpenSSL and does not form part of the OpenSSL public API. You should not be using any of the symbols contained within it - and none of those symbols are documented in the public documentation.
When linking statically it happens to work because those internal symbols are present in the static library. But they are not exported by the dll - and this is the reason why you are having problems.
In order to use the ChaCha20 algorithm you should be using the EVP_Encrypt*
and EVP_Decrypt*
APIs:
https://docs.openssl.org/master/man3/EVP_EncryptInit/
See also:
https://docs.openssl.org/master/man7/EVP_CIPHER-CHACHA/
There's demo code here:
https://github.com/openssl/openssl/blob/master/demos/cipher/ariacbc.c
That demo is for "ARIA-256-CBC", but you can simply replace that with "ChaCha20"