-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added initial RSA signing logic * Allowed export of RSA key * Added check for Signing Algorithm validity * Added tests for RSA signing * Updated README * Readme formatting * README update * Added RSA guide * Amended warning
- Loading branch information
Showing
12 changed files
with
2,821 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cmk | ||
|
||
type InvalidSigningAlgorithm struct {} | ||
func (v *InvalidSigningAlgorithm) Error() string { | ||
return "invalid signing algorithm" | ||
} | ||
|
||
//--- | ||
|
||
type InvalidDigestLength struct {} | ||
func (v *InvalidDigestLength) Error() string { | ||
return "invalid digest length" | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cmk | ||
|
||
import ( | ||
"crypto/sha256" | ||
"crypto/sha512" | ||
"errors" | ||
"hash" | ||
) | ||
|
||
func hashMessage(message []byte, algorithm SigningAlgorithm) ([]byte, error) { | ||
|
||
//-------------------------- | ||
// Hash the message | ||
|
||
var digest hash.Hash | ||
|
||
switch algorithm { | ||
case SigningAlgorithmEcdsaSha256, SigningAlgorithmRsaPssSha256, SigningAlgorithmRsaPkcsSha256: | ||
digest = sha256.New() | ||
case SigningAlgorithmEcdsaSha384, SigningAlgorithmRsaPssSha384, SigningAlgorithmRsaPkcsSha384: | ||
digest = sha512.New384() | ||
case SigningAlgorithmEcdsaSha512, SigningAlgorithmRsaPssSha512, SigningAlgorithmRsaPkcsSha512: | ||
digest = sha512.New() | ||
default: | ||
return []byte{}, errors.New("unknown signing algorithm") | ||
} | ||
|
||
digest.Write(message) | ||
return digest.Sum(nil), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.