Skip to content

Commit

Permalink
Wrap Algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbelvin committed Mar 19, 2021
1 parent 8ea63b0 commit fe9ad5f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
20 changes: 17 additions & 3 deletions commands/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,28 @@ func CreateGetPseudoRandomCommand(numBytes uint16) *CommandMessage {
return command
}

func CreatePutWrapkeyCommand(objID uint16, label []byte, domains uint16, capabilities, delegated uint64, wrapkey []byte) (*CommandMessage, error) {
func CreatePutWrapkeyCommand(objID uint16, label []byte, domains uint16, capabilities uint64, algorithm Algorithm, delegated uint64, wrapkey []byte) (*CommandMessage, error) {
if len(label) > LabelLength {
return nil, errors.New("label is too long")
}
if len(label) < LabelLength {
label = append(label, bytes.Repeat([]byte{0x00}, LabelLength-len(label))...)
}
if keyLen := len(wrapkey); keyLen != 16 && keyLen != 24 && keyLen != 32 {
return nil, errors.New("wrapkey is wrong length")
switch algorithm {
case AlgorithmAES128CCMWrap:
if keyLen := len(wrapkey); keyLen != 16 {
return nil, errors.New("wrapkey is wrong length")
}
case AlgorithmAES192CCMWrap:
if keyLen := len(wrapkey); keyLen != 24 {
return nil, errors.New("wrapkey is wrong length")
}
case AlgorithmAES256CCMWrap:
if keyLen := len(wrapkey); keyLen != 32 {
return nil, errors.New("wrapkey is wrong length")
}
default:
return nil, errors.New("invalid algorithm")
}

command := &CommandMessage{
Expand All @@ -269,6 +282,7 @@ func CreatePutWrapkeyCommand(objID uint16, label []byte, domains uint16, capabil
payload.Write(label)
binary.Write(payload, binary.BigEndian, domains)
binary.Write(payload, binary.BigEndian, capabilities)
binary.Write(payload, binary.BigEndian, algorithm)
binary.Write(payload, binary.BigEndian, delegated)
payload.Write(wrapkey)

Expand Down
3 changes: 3 additions & 0 deletions commands/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const (
AlgorithmSecp256k1 Algorithm = 15
AlgorithmYubicoAESAuthentication Algorithm = 38
AlgorighmED25519 Algorithm = 46
AlgorithmAES128CCMWrap Algorithm = 29
AlgorithmAES192CCMWrap Algorithm = 41
AlgorithmAES256CCMWrap Algorithm = 42

// Capabilities
CapabilityGetOpaque uint64 = 0x0000000000000001
Expand Down

0 comments on commit fe9ad5f

Please sign in to comment.