-
Notifications
You must be signed in to change notification settings - Fork 459
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
CryptAcquireContext, CryptGenRandom and CryptReleaseContext are deprecated #577
Comments
I've reimplemented the # CMakeLists.txt
if(MSVC)
target_link_libraries(tomcrypt PRIVATE Bcrypt)
endif() /* rng_get_bytes.c */
#include <bcrypt.h>
static unsigned long _rng_win32(unsigned char *buf, unsigned long len,
void (*callback)(void))
{
LTC_UNUSED_PARAM(callback);
BCRYPT_ALG_HANDLE hProv = 0;
if (!BCRYPT_SUCCESS(BCryptOpenAlgorithmProvider(&hProv, BCRYPT_RNG_ALGORITHM, NULL, 0))) {
return 0;
}
if (!BCRYPT_SUCCESS(BCryptGenRandom(hProv, buf, len, 0))) {
BCryptCloseAlgorithmProvider(hProv, 0);
return 0;
}
BCryptCloseAlgorithmProvider(hProv, 0);
return len;
} It compiles now, but I don't have a Windows machine here to test it. |
I'll try, I've got Windows to try it out (although I really want to avoid testing VS2008 for something like that), I happen to have VS2005 still installed, so I'll give it a try on that. Chances are it'll open the project and solution with only minor changes. Also at least for libraries like this one I'd probably use [1] That said, there are reasons why you may not want to do this without also providing an option to turn the behavior off. One being that if you ever request a dependency like this, the respective record ends up in the object file and ultimately a static lib and could annoy you if you wanted to supply the symbols any other way. |
I also noticed another function named What's off about the general code around these locations is that they default to |
@sjaeckel @leite @karel-m Could you please chime in exactly what you'd like to see here? I'd be happy to contribute the following changes on top of what @mabuchner has provided (building atop his work). The list below is intentionally numbered, so we can discuss the points. Some of those are more or less "policy" which is why I am asking you as (visible) libtom project members to chime in.
Thanks for any input you can provide, so I can get going. |
Thanks for picking this up! That plan sounds good. Regarding the solution files for newer VS versions than the 2008 we already have: please don't add this. We won't start adding a solution for each new VS version. If someone wants to use it in VS, they can convert the 2008 solution or simply use the Regarding VS2005: it should be sufficient to test via Regarding backwards compatibility: Sounds good! We can keep the existing implementation and use it for all Windows versions that don't have |
👍 ... and thanks for the swift response.
I can see why and this wasn't what I was proposing (one solution/project per VS major version). However, you should be aware that VS since around VS2010 has been using MSBuild under the hood. That's a departure from prior versions (incl. VS2008) and it would be good to offer some MSBuild-based project, since all these modern VS versions have structurally the same project file format. The conversion exists and works, but converted projects typically have some peculiarities embedded, such as property sheets which will suppress certain warnings or enable old (MSVC-specific) standard-violating behavior to not cause any "friction" when converting to the newer version. I looked over the auto-converted But I won't impose on you. I will anyway use a forked version of
The Makefile seems like a good idea in general (I love GNU make for other purposes), but when in Rome ... so I think a (modern) VS-based project is still the better option. But again, I won't impose. I'll work on this a bit, send a pull request and then we can hone it further to suit your needs.
Might work, yes. But with
Excellent. I hope I can make it work across a range of versions. However, one small wish: could we update the minimum to something like Windows XP? Theoretically the code does impose XP as minimum already in As an unrelated side note: I am working on amalgamating libtomcrypt and libtommath into a single Thanks. |
OK, IMO we can also replace the 2008 solution with a
OK!? even though it's an nmake file which is natively supported from VS?!
IMO: yes
Please feel free to bring both to the same state!
you know there's also a then there's https://github.com/eduardsui/tlse which already uses an outdated amalgamation of ltc and can maybe give some hints?
sure! as we're breaking API&ABI on develop anyways, we can clean everything up as required.
Thanks back to you :) |
I didn't even receive a notification of your last message, but I am now on it now. Sorry for the delay. |
@sjaeckel A few observations. Please note, I am starting with libtommath, as it's a prerequisite for libtomcrypt. It should be quicker to take the results from the former and apply them to the latter, once everything is in place. Since you seem to strive for extensive backward compatibility it's with great sadness (😉) I have to break it to you that even the unchanged solution/
There is indeed no such header in either of these VS versions. Alternatives exist. I'll pick one which creates the least noise on VS2003 through 2008 and is "license"-compatible. VS2010 allegedly has the header (haven't installed it as of yet). Further reading on the topic:
Clearly the presence of a VS2008 solution would suggest that one is able to build libtommath (in this case) using it. So perhaps not such a good idea to provide such an old solution. By the way, Anyway, making slow progress. I'll create a branch on my end, so I can rebase on Please also note that in all my tests I will use the very latest patch level of the VS versions available to me. If I feel like it (and find the time), I may even try it out with VS6 and the DDKs/WDKs 😁. PS: if you don't know this website, have a look at predef.sf.net for information on how to identify compilers, OSs and libraries etc. |
Also, I don't know how |
Oh I'm not sure if you misunderstood my statement here! I don't think we have to force compatibility to really ancient versions of VS with the Source-code compatibility is another question. IMO we don't have to build against such old versions if we keep the code intact and still compile it against some newer VS version. If someone really wants to use the libraries on such an old platform they can still disable those warnings or do whatever else is necessary to have a successful build. I don't see it as our duty to really test this. |
Ah, fair enough. However, now I've already done the bulk of it for libtommath, so it doesn't really hurt to go through it. Especially since I spent hours on end installing all VS versions between 2003 and 2022 (inclusive). The versions that I have not yet tested well are VS2010 through 2017, but I am on it. Edit: the nice part is that those old versions won't change. Even VS2017 is unlikely to see another release. So everything I find out about these versions will hold true in the future all the same. I have one question regarding your remark about
... for the The above could also be done more explicitly like:
|
This fixes #577 Patch inspired by the same, but simplified after reading the docs. Signed-off-by: Steffen Jaeckel <[email protected]>
This fixes #577 Patch inspired by the same, but simplified after reading the docs. Signed-off-by: Steffen Jaeckel <[email protected]>
This fixes #577 Patch inspired by the same, but simplified after reading the docs. Signed-off-by: Steffen Jaeckel <[email protected]>
This fixes #577 Patch inspired by the same, but simplified after reading the docs. Signed-off-by: Steffen Jaeckel <[email protected]>
Can you please check whether #626 correctly fixes this? |
Sorry, but I can't really test it anymore. Unfortunately, I had to find a new employer. Now I have neither access to my ex-employers codebase nor a Windows system. Thanks for taking the time to fix this issue. I'm sure it will benefit other developers. |
I'll try to have a look at the change from a Windows box tonight. PS: Sorry, but I lost sight of the other topic I had worked on, since libtomcrypt in the end didn't suit my needs for the particular issue, but I'll try to finish up my contribution to have proper solutions/projects for various VS versions. |
@sjaeckel took one day longer, but appears to work as desired from my tests. As far as I can tell this solves it. Compiles without warnings, and works when running it. PS: I also like that you went with a solution not requiring to initialize the crypto provider. |
This errors out on a fresh configure with Unknown CMake command "cmake_push_check_state" and Unknown CMake command "cmake_check_symbol_exists". This can be fixed with |
Reported by @pineappleiceberg in [0] [0] #577 (comment) Signed-off-by: Steffen Jaeckel <[email protected]>
On Windows libtomcrypt uses CryptAcquireContext, CryptGenRandom and CryptReleaseContext to generate random numbers.
https://github.com/libtom/libtomcrypt/blob/v1.18.2/src/prngs/rng_get_bytes.c#L105
According to the documentation here, here and here, those functions are deprecated.
In fact, I'm opening this issue, because I failed to compile libtomcrypt for UWP where those functions were already removed.
libtomcrypt should probably replace the deprecated functions with the mentioned Cryptography Next Generation API.
The text was updated successfully, but these errors were encountered: