GitXplorerGitXplorer
v

ed25519

public
19 stars
14 forks
1 issues

Commits

List of commits on branch master.
Unverified
c59b88c826c0db00f5c05214fa7b6c232ad4a55b

Create LICENSE

vvzsg committed 8 years ago
Unverified
fb50c0c76f039fa03ca15813feb691f8ec1b1a9f

Add README

vvzsg committed 8 years ago
Unverified
c43a81f1032f3a3b3c8ad54a95d79e852e56a003

Clean up internal interface

vvzsg committed 8 years ago
Unverified
4c613a1ed978c368438e13ecb41b2b9149d085ac

Add support for the add scalar operation

vvzsg committed 8 years ago
Unverified
8a9ef630a29823e01bf2f05ffd32ecfe2de026b2

Add initializer for constructing KeyPair from keys

vvzsg committed 8 years ago
Unverified
ace0f4027712e20c7c617b37ba16760d6cb6346e

Add CircleCI configuration

vvzsg committed 8 years ago

README

The README file for this repository.

Ed25519 for Swift 3.x

Swift CircleCI

This project is a Swift adaptation of the portable C Ed25519 implementation available here.
The complete functionality, including the key exchange and scalar addition functions are available.

On both macOS and Linux systems, /dev/urandom will be used for generating seeds.

Installation

To integrate the library in your SwiftPM project, add the following dependency to Package.swift:

.Package(url: "https://github.com/vzsg/ed25519.git", majorVersion: 0, minor: 1)

API

let seed = try Seed()

Creates a 32 byte random seed for key generation.
May throw Ed25519Error.seedGenerationFailed in case there was a problem with reading from /dev/urandom.

let seedBytes: [UInt8] = [ ... ]
let seed2 = try Seed(bytes: bytes)

Creates a seed for key generation with a previously known value.
bytes must be an array of 32 bytes, otherwise Ed25519Error.invalidSeedLength will be thrown.

let keyPair = KeyPair(seed: seed)

Creates a new key pair from the given seed.

let pubBytes: [UInt8] = [ ... ]
let privBytes: [UInt8] = [ ... ]
let keyPair2 = try KeyPair(publicKey: pubBytes, privateKey: privBytes)

Creates a key pair from the previously known public and private keys.
Throws Ed25519Error.invalidPublicKeyLength if the public key is not 32, or Ed25519Error.invalidPrivateKeyLength if the private key is not 64 bytes long.

let publicKey = try PublicKey(pubBytes)
let privateKey = try PrivateKey(privBytes)
let keyPair3 = KeyPair(publicKey: publicKey, privateKey: privateKey)

Construct public and private keys directly.
The same length limitations and exceptions apply.

publicKey.bytes
privateKey.bytes
keyPair.publicKey.bytes
keyPair.privateKey.bytes
seed.bytes

Access raw byte arrays behind any key or seed with the bytes property.

let message: [UInt8] = [ ... ]
let signature: [UInt8] = keyPair.sign(message: message)

Creates a signature of the given message with the given key pair.
signature will be an array of 64 bytes.

let valid: Bool = try keyPair.verify(signature: signature, message: message)
let valid2: Bool = try publicKey.verify(signature: signature, message: message)

Verifies the signature on the given message using a key pair or a public key.
Both methods throw Ed25519Error.invalidSignatureLength if signature is not an array of 64 bytes.

let scalar: [UInt8] = [ ... ]
let keyPairMod = try keyPair.add(scalar: scalar)
let publicKeyMod = try publicKey.add(scalar: scalar)
let privateKeyMod = try privateKey.add(scalar: scalar)

Adds scalar to the given key pair, public or private key, where scalar is a 32 byte buffer (possibly generated with a seed), generating new key(s). This is useful for enforcing randomness on a key pair by a third party while only knowing the public key, among other things. Warning: the last bit of the scalar is ignored - if comparing scalars make sure to ignore scalar[31].

let sharedSecret = keyPair.keyExchange()
let sharedSecret2 = try KeyPair.keyExchange(publicKey: pubBytes, privateKey: privBytes)
let sharedSecret3 = KeyPair.keyExchange(publicKey: publicKey, privateKey: privateKey)

Performs a key exchange on the given public key and private key, producing a shared secret, an array of 32 bytes. It is recommended to hash the shared secret before using it.

Example

Check the unit tests for usage examples.

License

The Swift library is released under the MIT license. See LICENSE for details.

The C implementation is (c) 2015 Orson Peters, licensed under the permissive zlib license.
The original source code is not modified, only reorganized for SwiftPM consumption.
See license.txt in CEd25519 for details.