Creating ECDSA keys with OpenSSL 3 (migration problem) - c++

I need to create ECDSA keys and used old OpenSSL code until now, which dosn't compile any more under OpenSSL3, there are now lots of deprecation errors. I invested now several days with search & try, but I can't solve it. I am trying the simple example [https://fm4dd.com/openssl/eckeycreate.shtm][1], but already the first lines create these errors:
WorkerThread.cpp(34,2): error C4996: 'ERR_load_BIO_strings': Since OpenSSL 3.0
WorkerThread.cpp(47,19): error C4996: 'EC_KEY_new_by_curve_name': Since OpenSSL 3.0
WorkerThread.cpp(54,2): error C4996: 'EC_KEY_free': Since OpenSSL 3.0
So the first idea would be to eliminate these compiler errors somehow. I found the switches
#define OPENSSL_API_COMPAT 30000
#define OPENSSL_NO_DEPRECATED
but they create even more errors, because now suddenly even the EC_KEY is unknown to the compiler. No solution.
So there stays the hard way to try to migrate the code somehow to OpenSSL3, because there seems to be no example code in the whole internet for simply creating an ECDSA key with OpenSSL3, and extract the private and public part. But just changing single functions with an OpenSSL3 matching function doesn't solve it, because the whole concept changes (switching from low level API to high level, with a completely different programming model).
I have tried fiddling around with lots of examples, but it looks like my programming task that seems so simple is a very complicated thing. Any help is appreciated, but I want to stay in C/C++ because my application is performance critical.
Environment: MS Win10, MS Visual Studio 2019, latest OpenSSL 3
[1]: https://fm4dd.com/openssl/eckeycreate.shtm

WorkerThread.cpp(34,2): error C4996: 'ERR_load_BIO_strings': Since OpenSSL 3.0
You don't need to call any of those initialisation functions. Just remove them from your code. They are not needed with any version of OpenSSL from 1.1.0 onwards.
In the example, all of the code for getting an EC_GROUP, creating an EC_KEY, generating a key, setting the OPENSSL_EC_NAMED_CURVE flag and assigning it to an EVP_PKEY can be completely removed. Replace it with a simple call to EVP_EC_gen(). See the man page here:
https://www.openssl.org/docs/man3.0/man3/EVP_EC_gen.html
E.g. all of that code can be replaced with something like
pkey = EVP_EC_gen("secp521r1");
if (pkey == NULL) {
BIO_printf(outbio, "Error generating the ECC key.");
abort();
}

Related

"USBSerial" has no member "printf" on STM32F411CEU6 in PlatformIO / ststm32

Trying to run this USB Serial example (bottom) to learn MBED, but I get the following compilation error:
class "USBSerial" has no member "printf"
Is it possible it isn't implemented for the STM32F411? Or is this a problem with MBED itself?
Seems like this should be basic functionality. Not finding much useful info on google when searching for this error. Has anyone else seen this error before?
potentially useful details:
IDE: vscode/platformIO
platformio.ini:
[env:nucleo f411re]
platform = ststm32
framework = mbed
board = nucleo_f411re
monitor_speed = 115200
MBED version: 6.2 (as I recall from memory, though I doubt it matters since I checked the docs for a few versions and the API and example appears unchanged)
The method printf() (which is a C, not C++ concept anyway) does not exist, simple as that. Use sprintf() if that's what you're familar with, then USBSerial.write(), perhaps.

After installing the 1.1.92.1 VulkanSDK xmemory0 and vector errors

After installing the 1.1.92.1 VulkanSDK xmemory0 and vector errors popped up and the project does not compile any more, bellow are the output errors from Visual Studio 2017. Going back to the previous 1.1.85.0 sdk version thought, it works again. Any idea what happens? Thanks.
Edit
<https://pastebin.com/94x8Lerq>
the error list is too big to include here, i m using this link
Edit2
It seems the way to enumerate stuff (at least the way i did it), has changed a bit, thus it explains those vector error i was getting.
Old way:
uint32_t gpuCount = 0;
vulkan.instance.enumeratePhysicalDevices(&gpuCount, nullptr);
std::vector<vk::PhysicalDevice> gpuList(gpuCount);
vulkan.instance.enumeratePhysicalDevices(&gpuCount, gpuList.data());
New way:
std::vector<vk::PhysicalDevice> gpuList = vulkan.instance.enumeratePhysicalDevices().value;
Since you are using vulkan.hpp, you could ask about this on their GitHub site. You could also diff vulkan.hpp between the two SDKs and note that there are differences in the file where enumeratePhysicalDevices is concerned.

C++ FatFs undefined reference to functions

I have a code written in Atmel Studio to read/write data from a SD card. I am using FatFs here. My problem is the code doesn't compile when I use some of the functions (f_chdir, f_getcwd...) in FatFs. Some functions works fine (f_puts, f_open, f_mount, f_mkdir...). All these functions are located in same header file (ff.h, ff.c)
The error says "undefined reference to -function-, ld returned 1 exit status". When I go to the error it shows the end of the code while it is suppose to show where the error is.
I cannot understand the problem with my code. Any help is appreciated.
Just ran into this using the SD card for a project using SAM4S Xplained Pro (Atmel 7, ASF 3.20).
Make sure you have all the asf projects (fatfs, sd_mmc, memory access control, and then the other basics e.g. pmc, gpio, and maybe a few more). My asf did NOT include sd_mmc_mem.c and sd_mmc_mem.h for some reason, so I had to include those myself. Also remember to do the sd_mmc_init() at the top of your main loop. As for the configuration...
If you look closely at ffconf.h, the first thing it does is include conf_fatfs.h, which (wait for it!) is EXACTLY the same file line by line as ffconf.h. All the variables are defined there first and foremost (and guarded by an #ifndef FFCONF and NOT an CONF_FATFS) aka that's where it counts..
Go into conf_fatfs.h and change _USE_STRFUNC to 1 or 2 et voila.
Also note that in the places where you use it, you'll have to #include the ff.h preceded by either ffconf.h or conf_access.h
ASF is a real snake pit if you don't know what you're looking for.
Enjoy.
By default, the memory control access interface is disabled in the ASF wizard. In order to enable the memory control access, please follow the steps below.
Open the ASF wizard (Alt + W).
Enable the Memory Control Access as follows.
ASF SD sd_mmc_mem.h memory access enable
Finally, click the “Apply” option to make the changes.
This adds sd_mmc_mem.h /.c files
Open the ffconf.h in your favorite editor and set _FS_RPATH to 2. From ffconf.h:
#define _FS_RPATH 0
/* This option configures relative path feature.
/
/ 0: Disable relative path feature and remove related functions.
/ 1: Enable relative path feature. f_chdir() and f_chdrive() are available.
/ 2: f_getcwd() function is available in addition to 1.
/
/ Note that directory items read via f_readdir() are affected by this option. */
Which features of the fatfs library are included in your build is configurable, so that you don't have to lose valuable ROM space (as well as a few bytes of RAM) for functions you're not using.
For versions of the FatFS library prior to 0.8a, _FS_RPATH supports only values 0 and 1; f_getcwd is not available in these versions.
Additionally, in versions prior to 0.8, it is necessary for C++ code to explicitly include its headers as C headers to avoid name mangling:
extern "C" {
#include "ff.h"
}
From version 0.8 onwards, it does this internally. You can find the new versions here if you're still working with an old one -- the comment you left leads me to believe that this might be the case.
Check if _FS_MINIMZE in ffconf.h is 0 to have all functions available.
In my version that I downloaded from elm-chan it was by default set to 3 and lead to the compiler error: undefined reference.
In file ffconf.h, set #define _USE_FIND to 1.
/* This option switches filtered directory read functions, f_findfirst() and
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
I needed to use f_findfirst() and f_findnext() functions and i was getting undefined reference errors.
Now this solved my problem.
Drive/directory handling functions are under #if _FS_RPATH >= 1 (or similar preprocessors) .

What is the setsockopt option name of TCP_USER_TIMEOUT on OSX

I'm trying to port some code over to OSX - it appears that setsockopt has a few differences from Linux. The one I've found and corrected so far is using TCP_KEEPALIVE instead of TCP_KEEPIDLE.
What is the equivalent to TCP_USER_TIMEOUT for OSX?
Using TCP_USER_TIMEOUT fails to compile and prints an undeclared identifier error
I find a macro named "TCP_CONNECTIONTIMEOUT" in tcp.h. I use it to replace TCP_USER_TIMEOUT on Mac. It works well. You may try it.
Another possible option is TCP_RXT_CONNDROPTIME from the same header:
#define TCP_RXT_CONNDROPTIME 0x80 /* time after which tcp retransmissions will be
* stopped and the connection will be dropped
*/
I've found this weird commit where there are three implementations provided for TCP_USER_TIMEOUT:
Linux: TCP_USER_TIMEOUT is set manually (seems like this code is quite outdated);
Darwin: TCP_RXT_CONNDROPTIME is used;
Win: no implementation provided.
This commit might be a clue, but I haven't tested it myself. I just hope that this information could be helpful to someone.
Check TCP_USER_TIMEOUT and TCP_CONNECTIONTIMEOUT descriptions in the Linux man and BSD man - they doesn't seem to be very similar.

Timed Indexed Color sets in CPN Tools that results in Unhandled Exception Error

I am using CPN Tools to model a distributed system. CPN Tools uses CPN ML an extension of SML. The project homepage is: cpntools.org
I started with a simple model and when I try to make a particular indexed color set timed, I get an "Internal error". There is another indexed colorset within my Petri-net model that is timed and works correctly. I am not sure how I can troubleshoot since I don't understand the error message. Could you help me interpret the error message or give me some hints on what I could be doing wrong?
The model is:
http://imgur.com/JUjPRHK
The declarations of the model are:
http://imgur.com/DvvpyvH
The error message is:
Internal error: Compile error when generating code. Caught error.../compiler/TopLevel/interact/evalloop.sml:296.17-296.20../compiler/TopLevel/interact/evalloop.sml:44.55../compiler/TopLevel/interact/evalloop.sml:66.19-66.27
structure CPN`TransitionID1413873858 = struct ... end (* see simulator debug info for full code *)
simglue.sml:884.12-884.43
"
Thank you~
I know this is an old question, but I run in the same problem and wasted too much time on this, so maybe it will help someone else in the future.
I didn't understand exactly the reason for this, but it seems the problem appears when you play with time values on an arch that ends to a transition (I was updating an integer value to the current time, using IntInf.toInt(time())). Now, if I move the code on the outgoing arch of that transition (that is: the one that ends in a place) there is no error.