A pure Python implemention of curve25519
Project description
x25519 (curve25519)
A pure Python implemention of curve25519 like Go package x/crypto/curve25519:
package main
import (
"fmt"
"bytes"
"golang.org/x/crypto/curve25519"
)
func main() {
var publicKey [32]byte
privateKey := (*[32]byte)(bytes.Repeat([]byte("1"), 32))
curve25519.ScalarBaseMult(&publicKey, privateKey)
fmt.Printf("%x\n", publicKey)
var sharedSecret [32]byte
peerPublicKey := (*[32]byte)(bytes.Repeat([]byte("2"), 32))
curve25519.ScalarMult(&sharedSecret, privateKey, peerPublicKey)
fmt.Printf("%x\n", sharedSecret)
}
/* output:
04f5f29162c31a8defa18e6e742224ee806fc1718a278be859ba5620402b8f3a
a6d830c3561f210fc006c77768369af0f5b3e3e502e74bd3e80991d7cb7bfa50
*/
Usage of this package:
# this code supports both python 2 and 3
from binascii import hexlify
import x25519
private_key = b'1' * 32
public_key = x25519.scalar_base_mult(private_key)
print(hexlify(public_key))
peer_public_key = b'2' * 32
shared_secret = x25519.scalar_mult(private_key, peer_public_key)
print(hexlify(shared_secret))
'''output:
b'04f5f29162c31a8defa18e6e742224ee806fc1718a278be859ba5620402b8f3a'
b'a6d830c3561f210fc006c77768369af0f5b3e3e502e74bd3e80991d7cb7bfa50'
'''
Generally, other C implementions are much faster:
import pysodium
private_key = b'1' * 32
public_key = pysodium.crypto_scalarmult_curve25519_base(private_key)
print(public_key.hex())
peer_public_key = b'2' * 32
shared_secret = pysodium.crypto_scalarmult_curve25519(private_key, peer_public_key)
print(shared_secret.hex())
'''output:
04f5f29162c31a8defa18e6e742224ee806fc1718a278be859ba5620402b8f3a
a6d830c3561f210fc006c77768369af0f5b3e3e502e74bd3e80991d7cb7bfa50
'''
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
x25519-0.0.2.tar.gz
(4.8 kB
view details)
Built Distribution
File details
Details for the file x25519-0.0.2.tar.gz
.
File metadata
- Download URL: x25519-0.0.2.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed91d0aba7f4f4959ed8b37118c11d94f56d36c38bb6f2e6c20d0438d75b1556 |
|
MD5 | 6ab1b6ac81cbe9458ffe6fdd18c9500b |
|
BLAKE2b-256 | c7b6fca895aff0800cdf941f856df0685a5513094163664b904576e3e3ef1460 |
File details
Details for the file x25519-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: x25519-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c0833260a548bea9137a5a1b5c30334b751a59d148a62832df0c9e7b919ce99 |
|
MD5 | 4372490d1bf42b345607783835104d2b |
|
BLAKE2b-256 | f2d166c637eb8e7a9601675bf7f04bb9a3015358a0f49e4c31d29a2b9a9d72d9 |