Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
crypto
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
crypto
Commits
21898bb1
Commit
21898bb1
authored
May 6, 2021
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Small refactor of method names in timestamp.go
parent
163060c4
No related branches found
No related tags found
1 merge request
!6
Release
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
registration/timestamp.go
+8
-8
8 additions, 8 deletions
registration/timestamp.go
registration/timestamp_test.go
+4
-4
4 additions, 4 deletions
registration/timestamp_test.go
with
12 additions
and
12 deletions
registration/timestamp.go
+
8
−
8
View file @
21898bb1
...
...
@@ -18,36 +18,36 @@ import (
// This file handles signature and verification logic of the timestamp for a user's verification.
// This is used to verify that a user has registered with the network at a specific data and time
// SignTimestamp signs a hash of the timestamp and the user's public key
func
SignTimestamp
(
rand
io
.
Reader
,
priv
*
rsa
.
PrivateKey
,
ts
time
.
Time
,
// Sign
With
Timestamp signs a hash of the timestamp and the user's public key
func
Sign
With
Timestamp
(
rand
io
.
Reader
,
priv
*
rsa
.
PrivateKey
,
ts
time
.
Time
,
userPubKey
*
rsa
.
PublicKey
)
([]
byte
,
error
)
{
// Construct the hash
options
:=
rsa
.
NewDefaultOptions
()
// Digest the timestamp and public key
hashedData
:=
digest
Timestamp
(
options
.
Hash
.
New
(),
ts
,
userPubKey
)
hashedData
:=
digest
(
options
.
Hash
.
New
(),
ts
,
userPubKey
)
// Sign the data
return
rsa
.
Sign
(
rand
,
priv
,
options
.
Hash
,
hashedData
,
options
)
}
// VerifyTimestamp verifies the signature provided against serverPubKey and the
// Verify
With
Timestamp verifies the signature provided against serverPubKey and the
// digest of the timestamp ts and userPubKey
func
VerifyTimestamp
(
sig
[]
byte
,
serverPubKey
*
rsa
.
PublicKey
,
func
Verify
With
Timestamp
(
sig
[]
byte
,
serverPubKey
*
rsa
.
PublicKey
,
ts
time
.
Time
,
userPubKey
*
rsa
.
PublicKey
)
error
{
// Construct the hash
options
:=
rsa
.
NewDefaultOptions
()
// Digest the timestamp and public key
hashedData
:=
digest
Timestamp
(
options
.
Hash
.
New
(),
ts
,
userPubKey
)
hashedData
:=
digest
(
options
.
Hash
.
New
(),
ts
,
userPubKey
)
// Verify the signature
return
rsa
.
Verify
(
serverPubKey
,
options
.
Hash
,
hashedData
,
sig
,
options
)
}
// digest
Timestamp
is a helper function which digests the timestamp ts and
// digest is a helper function which digests the timestamp ts and
// rsa.PublicKey userPubKey given hash h
func
digest
Timestamp
(
h
hash
.
Hash
,
ts
time
.
Time
,
userPubKey
*
rsa
.
PublicKey
)
[]
byte
{
func
digest
(
h
hash
.
Hash
,
ts
time
.
Time
,
userPubKey
*
rsa
.
PublicKey
)
[]
byte
{
// Serialize the public key
pubKeyBytes
:=
xx
.
PublicKeyBytes
(
&
(
*
userPubKey
)
.
PublicKey
)
...
...
This diff is collapsed.
Click to expand it.
registration/timestamp_test.go
+
4
−
4
View file @
21898bb1
...
...
@@ -122,7 +122,7 @@ func TestSignVerify(t *testing.T) {
}
// Sign data
sig
,
err
:=
SignTimestamp
(
notRand
,
serverPrivKey
,
testTime
,
userPrivKey
.
GetPublic
())
sig
,
err
:=
Sign
With
Timestamp
(
notRand
,
serverPrivKey
,
testTime
,
userPrivKey
.
GetPublic
())
if
err
!=
nil
{
t
.
Fatalf
(
"SignVerify error: "
+
"Could not sign data: %v"
,
err
.
Error
())
...
...
@@ -136,7 +136,7 @@ func TestSignVerify(t *testing.T) {
}
// Test the verification
err
=
VerifyTimestamp
(
sig
,
serverPrivKey
.
GetPublic
(),
testTime
,
userPrivKey
.
GetPublic
())
err
=
Verify
With
Timestamp
(
sig
,
serverPrivKey
.
GetPublic
(),
testTime
,
userPrivKey
.
GetPublic
())
if
err
!=
nil
{
t
.
Fatalf
(
"SignVerify error: "
+
"Could not verify signature: %v"
,
err
.
Error
())
...
...
@@ -156,14 +156,14 @@ func TestSignVerify(t *testing.T) {
"Could not generate key: %v"
,
err
.
Error
())
}
sig
,
err
=
SignTimestamp
(
notRand
,
serverPrivKey
,
testTime
,
userPrivKey
.
GetPublic
())
sig
,
err
=
Sign
With
Timestamp
(
notRand
,
serverPrivKey
,
testTime
,
userPrivKey
.
GetPublic
())
if
err
!=
nil
{
t
.
Fatalf
(
"SignVerify error: "
+
"Could not sign data: %v"
,
err
.
Error
())
}
// Test the verification
err
=
VerifyTimestamp
(
sig
,
serverPrivKey
.
GetPublic
(),
testTime
,
userPrivKey
.
GetPublic
())
err
=
Verify
With
Timestamp
(
sig
,
serverPrivKey
.
GetPublic
(),
testTime
,
userPrivKey
.
GetPublic
())
if
err
!=
nil
{
t
.
Fatalf
(
"SignVerify error: "
+
"Could not verify signature: %v"
,
err
.
Error
())
...
...
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