Skip to content

Commit

Permalink
Merge pull request certusone#1 from loomnetwork/secp256k1
Browse files Browse the repository at this point in the history
Added secp256k1 supporting
  • Loading branch information
mattkanwisher authored Dec 5, 2018
2 parents 2f4bdbb + 0717d04 commit fa21710
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 9 deletions.
27 changes: 27 additions & 0 deletions commands/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ func CreateSignDataEddsaCommand(keyID uint16, data []byte) (*CommandMessage, err
return command, nil
}

func CreateSignDataEcdsaCommand(keyID uint16, data []byte) (*CommandMessage, error) {
command := &CommandMessage{
CommandType: CommandTypeSignDataEcdsa,
}

payload := bytes.NewBuffer([]byte{})
binary.Write(payload, binary.BigEndian, keyID)
payload.Write(data)

command.Data = payload.Bytes()

return command, nil
}

func CreatePutAsymmetricKeyCommand(keyID uint16, label []byte, domains uint16, capabilities uint64, algorithm Algorithm, keyPart1 []byte, keyPart2 []byte) (*CommandMessage, error) {
if len(label) > LabelLength {
return nil, errors.New("label is too long")
Expand Down Expand Up @@ -124,6 +138,19 @@ func CreateGetPubKeyCommand(keyID uint16) (*CommandMessage, error) {
return command, nil
}

func CreateDeleteObjectCommand(objID uint16, objType uint8) (*CommandMessage, error) {
command := &CommandMessage{
CommandType: CommandTypeDeleteObject,
}

payload := bytes.NewBuffer([]byte{})
binary.Write(payload, binary.BigEndian, objID)
binary.Write(payload, binary.BigEndian, objType)
command.Data = payload.Bytes()

return command, nil
}

func CreateEchoCommand(data []byte) (*CommandMessage, error) {
command := &CommandMessage{
CommandType: CommandTypeEcho,
Expand Down
14 changes: 14 additions & 0 deletions commands/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ type (
Signature []byte
}

SignDataEcdsaResponse struct {
Signature []byte
}

GetPubKeyResponse struct {
Algorithm Algorithm
// KeyData can contain different formats depending on the algorithm according to the YubiHSM2 documentation.
Expand Down Expand Up @@ -82,12 +86,16 @@ func ParseResponse(data []byte) (Response, error) {
return parseCreateAsymmetricKeyResponse(payload)
case CommandTypeSignDataEddsa:
return parseSignDataEddsaResponse(payload)
case CommandTypeSignDataEcdsa:
return parseSignDataEcdsaResponse(payload)
case CommandTypePutAsymmetric:
return parsePutAsymmetricKeyResponse(payload)
case CommandTypeCloseSession:
return nil, nil
case CommandTypeGetPubKey:
return parseGetPubKeyResponse(payload)
case CommandTypeDeleteObject:
return nil, nil
case CommandTypeEcho:
return parseEchoResponse(payload)
case ErrorResponseCode:
Expand Down Expand Up @@ -149,6 +157,12 @@ func parseSignDataEddsaResponse(payload []byte) (Response, error) {
}, nil
}

func parseSignDataEcdsaResponse(payload []byte) (Response, error) {
return &SignDataEcdsaResponse{
Signature: payload,
}, nil
}

func parsePutAsymmetricKeyResponse(payload []byte) (Response, error) {
if len(payload) != 2 {
return nil, errors.New("invalid response payload length")
Expand Down
12 changes: 11 additions & 1 deletion commands/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ const (
ErrorCodeCommandUnexecuted ErrorCode = 0xff

// Algorithms
AlgorighmED25519 Algorithm = 46
AlgorithmSecp256k1 Algorithm = 15
AlgorighmED25519 Algorithm = 46

// Capabilities
CapabilityGetOpaque uint64 = 0x0000000000000001
Expand Down Expand Up @@ -145,4 +146,13 @@ const (
Domain14 uint16 = 0x2000
Domain15 uint16 = 0x4000
Domain16 uint16 = 0x8000

// object types
ObjectTypeOpaque uint8 = 0x01
ObjectTypeAuthenticationKey uint8 = 0x02
ObjectTypeAsymmetricKey uint8 = 0x03
ObjectTypeWrapKey uint8 = 0x04
ObjectTypeHmacKey uint8 = 0x05
ObjectTypeTemplate uint8 = 0x06
ObjectTypeOtpAeadKey uint8 = 0x07
)
2 changes: 1 addition & 1 deletion connector/connector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package connector

import "github.com/certusone/yubihsm-go/commands"
import "github.com/loomnetwork/yubihsm-go/commands"

type (
// Connector implements a simple request interface with a YubiHSM2
Expand Down
3 changes: 2 additions & 1 deletion connector/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package connector
import (
"bytes"
"fmt"
"github.com/certusone/yubihsm-go/commands"
"io/ioutil"
"net/http"
"strings"

"github.com/loomnetwork/yubihsm-go/commands"
)

type (
Expand Down
7 changes: 4 additions & 3 deletions manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package yubihsm
import (
"bytes"
"errors"
"github.com/certusone/yubihsm-go/commands"
"github.com/certusone/yubihsm-go/connector"
"github.com/certusone/yubihsm-go/securechannel"
"sync"
"time"

"github.com/loomnetwork/yubihsm-go/commands"
"github.com/loomnetwork/yubihsm-go/connector"
"github.com/loomnetwork/yubihsm-go/securechannel"
)

type (
Expand Down
7 changes: 4 additions & 3 deletions securechannel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"crypto/rand"
"encoding/binary"
"errors"
"github.com/certusone/yubihsm-go/commands"
"github.com/certusone/yubihsm-go/connector"
"github.com/enceve/crypto/cmac"
"sync"

"github.com/enceve/crypto/cmac"
"github.com/loomnetwork/yubihsm-go/commands"
"github.com/loomnetwork/yubihsm-go/connector"
)

type (
Expand Down

0 comments on commit fa21710

Please sign in to comment.