aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-04-17 10:41:58 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-04-17 10:41:58 +0200
commite51b73902a75cca2c5e042cea9b4807e037c02a5 (patch)
treefe52447341a8cf22e51f21b30992c37ca4b936f6
parent085b7cefaf1dd667294488658bacd95ea20828ae (diff)
Add sign and verify
-rw-r--r--keys.go19
1 files changed, 16 insertions, 3 deletions
diff --git a/keys.go b/keys.go
index 987f6b6..d4c2e49 100644
--- a/keys.go
+++ b/keys.go
@@ -54,11 +54,24 @@ func (v *PubKey) IsValid() bool {
return v.PKAlg == PKAlg
}
-func (v *EncKey) IsValid(pass []byte) bool {
- if v.PKAlg != PKAlg {
+func (v *PubKey) Verify(message []byte, sig *Sig) bool {
+ if v.PKAlg != sig.PKAlg || v.KeyNum != sig.KeyNum {
return false
}
- if v.KDFAlg != KDFAlg {
+ return ed25519.Verify(ed25519.PublicKey(v.PubKey[:]), message, sig.Sig[:])
+}
+
+func (v *EncKey) Sign(message []byte) *Sig {
+ sig := &Sig{
+ PKAlg: v.PKAlg,
+ KeyNum: v.KeyNum,
+ }
+ copy(sig.Sig[:], ed25519.Sign(ed25519.PrivateKey(v.SecKey[:]), message))
+ return sig
+}
+
+func (v *EncKey) IsValid(pass []byte) bool {
+ if v.PKAlg != PKAlg || v.KDFAlg != KDFAlg {
return false
}
if v.KDFRounds > 0 {