Public key implementation in C for Linux

2020-07-18 02:32发布

I'm trying to use public key crypto to sign and later verify a file. The file is a simple plaintext file that contains user information for authoring purposes.

I tried different sites for a C implementation of a public key crypto algorithm but I haven't found anything. A lot of sites point to using certificates (x.509, etc) but that is way beyond what I need. I am just looking for a way to generate and public and private keys and use a relatively well known algorithm to sign and verify a file.

Any pointers to a pure C implementation out there? The focus is on code that I can reuse and not external libs. The main problem being that I don't want to have to link against a full lib and its dependencies in order to have a very basic public key system.

Thanks.

5条回答
何必那么认真
2楼-- · 2020-07-18 02:57

The answers on this question contain some interesting links to other libraries.

However, I remember that there exists some reference source code in C for RSA and private key cryptography. I will add a link as soon as I have found it ;-)

EDIT

I just found "this link" (http://www.hackchina.com/en/cont/93068 - open on your own risk) - not sure about the source and details of that code. But, however, in the past the link to the original RSA reference implementation was contained somewhere in OpenSSL source or its documentation. Which is based on cryptsoft.com's library. I am sure the source can still be found somewhere on www.rsa.com/rsalabs/ - but I could not find it, and I am running out of time for now. Good luck ;-)

查看更多
萌系小妹纸
3楼-- · 2020-07-18 02:58

You may want to look at the well-respected, debugged, and tested OpenSSL libraries. Although OpenSSL is primarily for SSL/TLS networking, it contains extremely good implementations of many cryptographic protocols, which are often used by themselves for general cryptography.

Hope this helps!

查看更多
forever°为你锁心
4楼-- · 2020-07-18 02:59

OpenSSL is a very good package. You can just use the crypto library portion, which provides basic RSA implementations. That might be in line with what you are looking for.

Cryptlib is another alternative that could work for you. It has some strange licensing issues though, so consider those depending on how you will be using it.

Crypto++ is a set of different crypto technologies, and includes RSA, so you might try that.

Finally, RSA is not terribly complex to implement, so you could even implement it yourself using GMP, which provides the necessary mathematical functions you would need.

查看更多
倾城 Initia
5楼-- · 2020-07-18 03:05

I think that there was an answer[1] that fitted your question on :: Small RSA or DSA lib without dependencies

You may find LibTomCrypt useful. It's written in C, supports RSA and DSA (along with a host of other algorithms), and is public domain software. You can read about its features here: http://libtom.org/?page=features

[1] https://stackoverflow.com/a/1735526/68338 ( courtesy of https://stackoverflow.com/users/33837/emerick-rogul )

查看更多
放我归山
6楼-- · 2020-07-18 03:17

DJ Bernstein's curve25519 lets you create public/private key pairs. It does not have functions for signing, but you should be able to figure that part out with not too much hassle.

Update: In the mean time, there's also Ed25519 which already has the signature generation stuff figured out, without you having to jump through hoops. Same author, same availability of software (also e.g. "Donna" implementation and python binding), same ease of use, comparable speed.

The original implementation as well as the "Donna" implementation are both available under very liberal licenses.

You need to compile one file and call exactly one function to generate a key pair, and it's very fast. No obscure requirements for the public key. All one ever needs for some "cheap, fast, easy public key crypto".

查看更多
登录 后发表回答