Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the command SignDataPSS. #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Currently the following commands are implemented:
* GenerateAsymmetricKey
* SignDataEddsa
* SignDataPkcs1
* SignDataPss
* PutAsymmetricKey
* GetPubKey
* DeriveEcdh
Expand Down
22 changes: 22 additions & 0 deletions commands/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,28 @@ func CreateSignDataPkcs1Command(keyID uint16, data []byte) (*CommandMessage, err
return command, nil
}


// CreateSignDataPSSCommand creates the SignDataPSSCommand message.
// The payload is as follows:
// keyID | mfg1HashAlg | saltLength | digestedData
// Protocol details can be found here:
// https://docs.yubico.com/hardware/yubihsm-2/hsm-2-user-guide/hsm2-cmd-reference.html#id478
func CreateSignDataPSSCommand(keyID uint16, mfg1HashAlg Algorithm, saltLength uint16, digestedData []byte) (*CommandMessage, error) {
command := &CommandMessage{
CommandType: CommandTypeSignDataPss,
}

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

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
17 changes: 17 additions & 0 deletions commands/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ type (
Signature []byte
}

SignDataPSSResponse struct {
Signature []byte
}

SignDataEcdsaResponse struct {
Signature []byte
}
Expand Down Expand Up @@ -167,6 +171,8 @@ func ParseResponse(data []byte) (Response, error) {
return parseSignDataEcdsaResponse(payload)
case CommandTypeSignDataPkcs1:
return parseSignDataPkcs1Response(payload)
case CommandTypeSignDataPss:
return parseSignDataPSSResponse(payload)
case CommandTypePutAsymmetric:
return parsePutAsymmetricKeyResponse(payload)
case CommandTypeListObjects:
Expand Down Expand Up @@ -292,6 +298,17 @@ func parseSignDataPkcs1Response(payload []byte) (Response, error) {
}, nil
}

func parseSignDataPSSResponse(payload []byte) (Response, error) {
if len(payload) < 1 {
return nil, errors.New("invalid response payload length")
}

return &SignDataPSSResponse{
Signature: payload,
}, nil
}


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