Skip to content

Commit

Permalink
添加 EC-GDSA
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Aug 20, 2024
1 parent 43a4e80 commit 5422a5c
Show file tree
Hide file tree
Showing 9 changed files with 1,050 additions and 40 deletions.
42 changes: 42 additions & 0 deletions ecgdsa/curves.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ecgdsa

import (
"encoding/asn1"
"crypto/elliptic"
)

type namedCurveInfo struct {
namedCurve elliptic.Curve
oid asn1.ObjectIdentifier
}

var namedCurves = make([]namedCurveInfo, 0)

func AddNamedCurve(curve elliptic.Curve, oid asn1.ObjectIdentifier) {
namedCurves = append(namedCurves, namedCurveInfo{
namedCurve: curve,
oid: oid,
})
}

func NamedCurveFromOid(oid asn1.ObjectIdentifier) elliptic.Curve {
for i := range namedCurves {
cur := &namedCurves[i]
if cur.oid.Equal(oid) {
return cur.namedCurve
}
}

return nil
}

func OidFromNamedCurve(curve elliptic.Curve) (asn1.ObjectIdentifier, bool) {
for i := range namedCurves {
cur := &namedCurves[i]
if cur.namedCurve == curve {
return cur.oid, true
}
}

return asn1.ObjectIdentifier{}, false
}
Loading

0 comments on commit 5422a5c

Please sign in to comment.