This article is a mirror article of machine translation, please click here to jump to the original article.

View: 1525|Reply: 3

Curve25519 encryption algorithm

[Copy link]
Posted on 2025-2-12 17:05:02 | | | |
urve25519 is the highest level of Diffie-Hellman function available for a wide range of scenarios, designed by Professor Daniel J. Bernstein. In cryptography, Curve25519 is an elliptic curve that provides 128-bit security and is designed for use with the elliptic curve Diffie-Hellman (ECDH) key negotiation scheme. It is one of the fastest ECC curves and is not covered by any known patents.

Given a user's 32-byte key, curve25519 calculates the user's 32-byte public key. Given that user's 32-byte key and another user's 32-byte public key, curve25519 calculates a 32-byte shared key for both users to use. This secret can then be used to authenticate and encrypt information for both users.

2. Download and compile Curve25519

The curve25519 library computes the curve25519 function at a very high speed. The library has a wide range of applications. You can and should apply it in your own program instead of linking to a shared library; The compiled code is about 16KB, depending on the CPU.

Download and compile

Download

compile


3. Use Curve25519

For any C program that will use curve25519, modify the program to include curve25519.h, and modify the makefile to link the program with curve25519.a and state that the program depends on curve25519.a and curve25519.h.

Compute keys

Internally, to generate a 32-byte curve25519 key, first generate a secret of 32 random bytes from a cryptographic security source: mysecret[0], mysecret[1], ..., mysecret[31]. Then do as follows:
mysecret[0] &= 248;
mysecret[31] &= 127;
mysecret[31] |= 64;
Generate a 32-byte Curve25519 key mysecret[0], mysecret[1], ..., mysecret[31].

In the future, the library version will support a curve25519_ compression function that compresses 128 bytes of hashing into 32 bytes, adding some protection against insufficient random number generators; A curve25519_ clamp function that converts 32 bytes into a key; and an easiest to use combination of curve25519_ key generation functions, which directly convert 128 bytes into keys.

Compute public keys

To generate a 32Byte public key that matches the 32Byte key mypublic[0], mypublic[1], ..., mypublic[31], call the function
curve25519(mypublic,mysecret,basepoint);
where the constant basepoint is:

const unsigned char basepoint[32] = {9};
Future versions of the library will support more concise curve25519_ public functions.

Generate a shared key

Given another user's Curve25519 public key hispublic[0], hispublic[1], ..., hispublic[31], call

curve25519(shared,mysecret,hispublic);
Generate 32-byte shared keys shared[0], shared[1], ..., shared[31]. Another person can generate the same shared key based on their own private key as well as your public key.
Then both of you can hash this shared key and use the result as a key, for example for Poly1305-AES.
Future versions of the library will support a curve25519_ extension function that directly hashes a 32Byte key to generate 128 bytes as a key, and is the easiest to use, a combination curve25519_ shared function.

4. reference

[Ed25519 and Curve25519 explained]The hyperlink login is visible.
[Curve25519 encryption and decryption and ED25519 use of signatures]The hyperlink login is visible.
[ED25519]The hyperlink login is visible.
[Android ED25519 implementation]The hyperlink login is visible.
[[ED25519 C implementation]The hyperlink login is visible.
[ed25519 Java implementation]The hyperlink login is visible.

Original:The hyperlink login is visible.




Previous:Angular 18 Series (Thirty-One) VS Code Development Assistance Plugin
Next:NVIDIA Project DIGITS personal AI supercomputer
 Landlord| Posted on 2025-2-12 17:07:50 |
.NET/C# implementation code:


Test




Curve25519.cs (31 KB, Number of downloads: 1, 售价: 10 粒MB)
Posted on 2025-2-13 16:26:18 |
Looks good, support it.
Posted on 2025-2-14 09:51:22 |
Looks good, support it
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com