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

add support for decrypt RSA OAEP #28

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 @@ -14,6 +14,7 @@ Currently the following commands are implemented:
* PutAsymmetricKey
* GetPubKey
* DeriveEcdh
* DecryptOaep
* Echo
* ChangeAuthenticationKey
* PutAuthenticationKey
Expand Down
18 changes: 18 additions & 0 deletions commands/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,24 @@ func CreateDeriveEcdhCommand(objID uint16, pubkey []byte) (*CommandMessage, erro
return command, nil
}

func CreateDecryptOaepCommand(objID uint16, algorithm Algorithm, ciphertextFile []byte) (*CommandMessage, error) {
if algorithm < AlgorithmRSAOAEPSHA1 || algorithm > AlgorithmRSAOAEPSHA512 {
return nil, errors.New("invalid algorithm")
}

command := &CommandMessage{
CommandType: CommandTypeDecryptOaep,
}

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

return command, nil
}

func CreateChangeAuthenticationKeyCommand(objID uint16, newPassword string) (*CommandMessage, error) {
command := &CommandMessage{
CommandType: CommandTypeChangeAuthenticationKey,
Expand Down
12 changes: 12 additions & 0 deletions commands/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ type (
XCoordinate []byte
}

DecryptOaepResponse struct {
Plaintext []byte
}

ChangeAuthenticationKeyResponse struct {
ObjectID uint16
}
Expand Down Expand Up @@ -183,6 +187,8 @@ func ParseResponse(data []byte) (Response, error) {
return parseEchoResponse(payload)
case CommandTypeDeriveEcdh:
return parseDeriveEcdhResponse(payload)
case CommandTypeDecryptOaep:
return parseDecryptOaepResponse(payload)
case CommandTypeChangeAuthenticationKey:
return parseChangeAuthenticationKeyResponse(payload)
case CommandTypeGetPseudoRandom:
Expand Down Expand Up @@ -364,6 +370,12 @@ func parseDeriveEcdhResponse(payload []byte) (Response, error) {
}, nil
}

func parseDecryptOaepResponse(payload []byte) (Response, error) {
return &DecryptOaepResponse{
Plaintext: payload,
}, nil
}

func parseChangeAuthenticationKeyResponse(payload []byte) (Response, error) {
if len(payload) != 2 {
return nil, errors.New("invalid response payload length")
Expand Down