Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Dunitrust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nodes
rust
Dunitrust
Commits
9153eb84
Commit
9153eb84
authored
7 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
#13
use KeyPair in doc and ed25519 generator
parent
00650c8a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
keys/ed25519.rs
+9
-11
9 additions, 11 deletions
keys/ed25519.rs
keys/lib.rs
+6
-6
6 additions, 6 deletions
keys/lib.rs
with
15 additions
and
17 deletions
keys/ed25519.rs
+
9
−
11
View file @
9153eb84
...
...
@@ -217,7 +217,7 @@ pub struct KeyPair {
/// Store a Ed25519 public key.
pub
pubkey
:
PublicKey
,
/// Store a Ed25519 private key.
privkey
:
PrivateKey
,
pub
privkey
:
PrivateKey
,
}
impl
Display
for
KeyPair
{
...
...
@@ -236,14 +236,9 @@ impl Eq for KeyPair {}
impl
super
::
KeyPair
for
KeyPair
{
type
Signature
=
Signature
;
fn
new
(
password
:
&
[
u8
],
salt
:
&
[
u8
])
->
KeyPair
{
fn
from_passwd_and_salt
(
password
:
&
[
u8
],
salt
:
&
[
u8
])
->
KeyPair
{
let
generator
=
self
::
KeyPairGenerator
::
with_default_parameters
();
let
(
privkey
,
pubkey
)
=
generator
.generate
(
password
,
salt
);
KeyPair
{
pubkey
,
privkey
}
generator
.generate
(
password
,
salt
)
}
fn
sign
(
&
self
,
message
:
&
[
u8
])
->
Signature
{
Signature
(
crypto
::
ed25519
::
signature
(
message
,
&
self
.privkey
.0
))
...
...
@@ -286,7 +281,7 @@ impl KeyPairGenerator {
///
/// The [`PublicKey`](struct.PublicKey.html) will be able to verify messaged signed with
/// the [`PrivateKey`](struct.PrivateKey.html).
pub
fn
generate
(
&
self
,
password
:
&
[
u8
],
salt
:
&
[
u8
])
->
(
PrivateKey
,
PublicKey
)
{
pub
fn
generate
(
&
self
,
password
:
&
[
u8
],
salt
:
&
[
u8
])
->
KeyPair
{
let
mut
seed
=
[
0u8
;
32
];
crypto
::
scrypt
::
scrypt
(
password
,
...
...
@@ -296,7 +291,10 @@ impl KeyPairGenerator {
);
let
(
private
,
public
)
=
crypto
::
ed25519
::
keypair
(
&
seed
);
(
PrivateKey
(
private
),
PublicKey
(
public
))
KeyPair
{
pubkey
:
PublicKey
(
public
),
privkey
:
PrivateKey
(
private
),
}
}
}
...
...
@@ -436,7 +434,7 @@ Timestamp: 0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855
#[test]
fn
keypair_generate_sign_and_verify
()
{
let
keypair
=
super
::
KeyPair
::
new
(
"password"
.as_bytes
(),
"salt"
.as_bytes
());
let
keypair
=
super
::
KeyPair
::
from_passwd_and_salt
(
"password"
.as_bytes
(),
"salt"
.as_bytes
());
let
message
=
"Version: 10
Type: Identity
...
...
This diff is collapsed.
Click to expand it.
keys/lib.rs
+
6
−
6
View file @
9153eb84
...
...
@@ -21,21 +21,21 @@
//! # Usage
//!
//! ```
//! use duniter_keys::{Signature, PublicKey, PrivateKey};
//! use duniter_keys::{Signature, PublicKey, PrivateKey
, KeyPair
};
//! use duniter_keys::ed25519::KeyPairGenerator;
//!
//! let generator = KeyPairGenerator::with_default_parameters();
//!
//! let
(private_key, public_key)
= generator.generate(
//! let
keypair
= generator.generate(
//! b"password",
//! b"salt"
//! );
//!
//! let message = "Hello, world!";
//!
//! let signature =
private_key
.sign(&message.as_bytes());
//! let signature =
keypair
.sign(&message.as_bytes());
//!
//! assert!(
public_
key.verify(&message.as_bytes(), &signature));
//! assert!(
keypair.pub
key.verify(&message.as_bytes(), &signature));
//! ```
//!
//! # Format
...
...
@@ -153,8 +153,8 @@ pub trait KeyPair: Clone + Display + Debug + PartialEq + Eq {
/// Signature type of associated cryptosystem.
type
Signature
:
Signature
;
///
Cre
ate a new KeyPair
fn
new
(
password
:
&
[
u8
],
salt
:
&
[
u8
])
->
Self
;
///
Gener
ate a new KeyPair
from passwd and salt
fn
from_passwd_and_salt
(
password
:
&
[
u8
],
salt
:
&
[
u8
])
->
Self
;
/// Sign a message with privkey.
fn
sign
(
&
self
,
message
:
&
[
u8
])
->
Self
::
Signature
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment