ADDED: ed25519_new_keypair/1 to dynamically create a new Ed25519 key pair
This commit is contained in:
@@ -293,7 +293,8 @@ pub enum SystemClauseType {
|
|||||||
CryptoDataEncrypt,
|
CryptoDataEncrypt,
|
||||||
CryptoDataDecrypt,
|
CryptoDataDecrypt,
|
||||||
Ed25519Sign,
|
Ed25519Sign,
|
||||||
Ed25519Verify
|
Ed25519Verify,
|
||||||
|
Ed25519NewKeyPair
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SystemClauseType {
|
impl SystemClauseType {
|
||||||
@@ -484,6 +485,7 @@ impl SystemClauseType {
|
|||||||
&SystemClauseType::CryptoDataDecrypt => clause_name!("$crypto_data_decrypt"),
|
&SystemClauseType::CryptoDataDecrypt => clause_name!("$crypto_data_decrypt"),
|
||||||
&SystemClauseType::Ed25519Sign => clause_name!("$ed25519_sign"),
|
&SystemClauseType::Ed25519Sign => clause_name!("$ed25519_sign"),
|
||||||
&SystemClauseType::Ed25519Verify => clause_name!("$ed25519_verify"),
|
&SystemClauseType::Ed25519Verify => clause_name!("$ed25519_verify"),
|
||||||
|
&SystemClauseType::Ed25519NewKeyPair => clause_name!("$ed25519_new_keypair")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -654,6 +656,7 @@ impl SystemClauseType {
|
|||||||
("$crypto_data_decrypt", 5) => Some(SystemClauseType::CryptoDataDecrypt),
|
("$crypto_data_decrypt", 5) => Some(SystemClauseType::CryptoDataDecrypt),
|
||||||
("$ed25519_sign", 3) => Some(SystemClauseType::Ed25519Sign),
|
("$ed25519_sign", 3) => Some(SystemClauseType::Ed25519Sign),
|
||||||
("$ed25519_verify", 3) => Some(SystemClauseType::Ed25519Verify),
|
("$ed25519_verify", 3) => Some(SystemClauseType::Ed25519Verify),
|
||||||
|
("$ed25519_new_keypair", 1) => Some(SystemClauseType::Ed25519NewKeyPair),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
crypto_password_hash/3, % +Password, -Hash, +Options
|
crypto_password_hash/3, % +Password, -Hash, +Options
|
||||||
crypto_data_encrypt/6, % +PlainText, +Algorithm, +Key, +IV, -CipherText, +Options
|
crypto_data_encrypt/6, % +PlainText, +Algorithm, +Key, +IV, -CipherText, +Options
|
||||||
crypto_data_decrypt/6, % +CipherText, +Algorithm, +Key, +IV, -PlainText, +Options
|
crypto_data_decrypt/6, % +CipherText, +Algorithm, +Key, +IV, -PlainText, +Options
|
||||||
|
ed25519_new_keypair/1, % -KeyPair
|
||||||
ed25519_sign/4, % +PrivateKey, +Data, -Signature, +Options
|
ed25519_sign/4, % +PrivateKey, +Data, -Signature, +Options
|
||||||
ed25519_verify/4, % +PublicKey, +Data, -Signature, +Options
|
ed25519_verify/4, % +PublicKey, +Data, -Signature, +Options
|
||||||
crypto_name_curve/2, % +Name, -Curve
|
crypto_name_curve/2, % +Name, -Curve
|
||||||
@@ -630,28 +631,37 @@ encoding_bytes(utf8, Cs, Bs) :-
|
|||||||
Digital signatures with Ed25519
|
Digital signatures with Ed25519
|
||||||
===============================
|
===============================
|
||||||
|
|
||||||
ed25519_sign(+Key, +Data, -Signature, +Options)
|
- ed25519_new_keypair(-Pair)
|
||||||
|
Yields a new Ed25519 key pair Pair, a list of characters. The
|
||||||
|
pair contains the private key and must be kept absolutely secret.
|
||||||
|
Pair can be used for signing. Its public key can be obtained
|
||||||
|
with ed25519_keypair_public_key/2.
|
||||||
|
|
||||||
Key and Data must be lists of characters. Key is a private key in
|
- ed25519_keypair_public_key(+Pair, -PublicKey)
|
||||||
PKCS#8 (v1 or v2) DER format. Sign Data with Key, yielding
|
PublicKey is the public key of the given key pair. The public key
|
||||||
Signature as a list of hexadecimal characters.
|
can be used for signature verification, and can be shared freely.
|
||||||
|
|
||||||
|
- ed25519_sign(+Key, +Data, -Signature, +Options)
|
||||||
|
Key and Data must be lists of characters. Key is a private key or
|
||||||
|
key pair in PKCS#8 (v1 or v2) DER format. Sign Data with Key,
|
||||||
|
yielding Signature as a list of hexadecimal characters.
|
||||||
|
|
||||||
ed25519_verify(+Key, +Data, +Signature, +Options)
|
- ed25519_verify(+Key, +Data, +Signature, +Options)
|
||||||
|
Key and Data must be lists of characters. Key is a public key.
|
||||||
|
Succeeds if Data was signed with the private key corresponding to
|
||||||
|
Key, where Signature is a list of hexadecimal characters as
|
||||||
|
generated by ed25519_sign/4. Fails otherwise.
|
||||||
|
|
||||||
Key and Data must be lists of characters. Key is a public key in
|
Currently, the only option for signing and verifying is:
|
||||||
PKCS#8 DER format. Succeeds if Data was signed with the private key
|
|
||||||
corresponding to Key, where Signature is a list of hexadecimal
|
|
||||||
characters as generated by ed25519_sign/4. Fails otherwise.
|
|
||||||
|
|
||||||
|
|
||||||
Currently, the only option for both predicates is:
|
|
||||||
|
|
||||||
- encoding(+Encoding)
|
- encoding(+Encoding)
|
||||||
The default encoding of Data is utf8. The alternative is octet,
|
The default encoding of Data is utf8. The alternative is octet,
|
||||||
which treats Data as a list of raw bytes.
|
which treats Data as a list of raw bytes.
|
||||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
|
ed25519_new_keypair(Pair) :-
|
||||||
|
'$ed25519_new_keypair'(Pair).
|
||||||
|
|
||||||
ed25519_sign(Key0, Data0, Signature, Options) :-
|
ed25519_sign(Key0, Data0, Signature, Options) :-
|
||||||
options_data_bytes(Options, Data0, Data),
|
options_data_bytes(Options, Data0, Data),
|
||||||
encoding_bytes(octet, Key0, Key),
|
encoding_bytes(octet, Key0, Key),
|
||||||
|
|||||||
@@ -5448,6 +5448,15 @@ impl MachineState {
|
|||||||
|
|
||||||
self.unify(self[temp_v!(5)], complete_string);
|
self.unify(self[temp_v!(5)], complete_string);
|
||||||
}
|
}
|
||||||
|
&SystemClauseType::Ed25519NewKeyPair => {
|
||||||
|
let pkcs8_bytes = signature::Ed25519KeyPair::generate_pkcs8(rng()).unwrap();
|
||||||
|
let complete_string = {
|
||||||
|
let buffer = String::from_iter(pkcs8_bytes.as_ref().iter().map(|b| *b as char));
|
||||||
|
self.heap.put_complete_string(&buffer)
|
||||||
|
};
|
||||||
|
|
||||||
|
self.unify(self[temp_v!(1)], complete_string);
|
||||||
|
}
|
||||||
&SystemClauseType::Ed25519Sign => {
|
&SystemClauseType::Ed25519Sign => {
|
||||||
let stub1 = MachineError::functor_stub(clause_name!("ed25519_sign"), 4);
|
let stub1 = MachineError::functor_stub(clause_name!("ed25519_sign"), 4);
|
||||||
let key = self.integers_to_bytevec(temp_v!(1), stub1);
|
let key = self.integers_to_bytevec(temp_v!(1), stub1);
|
||||||
|
|||||||
Reference in New Issue
Block a user