-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from GaloisInc/98-hash-interface
Add interface for fixed-length hash functions
- Loading branch information
Showing
9 changed files
with
116 additions
and
39 deletions.
There are no files selected for viewing
12 changes: 0 additions & 12 deletions
12
Primitive/Asymmetric/Signature/ECDSA/Instantiations/ECDSA_P256.cry
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
Primitive/Asymmetric/Signature/ECDSA/Instantiations/ECDSA_P256_SHA256.cry
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,11 @@ | ||
/* | ||
* Instantiate ECDSA with curve P-256 (also known as secp256p1) and SHA256. | ||
* | ||
* @copyright Galois, Inc. | ||
* @author Marcella Hastings <[email protected]> | ||
*/ | ||
module Primitive::Asymmetric::Signature::ECDSA::Instantiations::ECDSA_P256_SHA256 = | ||
Primitive::Asymmetric::Signature::ECDSA::Specification { | ||
EC = Common::EC::PrimeField::Instantiations::P256, | ||
Hash = Primitive::Keyless::Hash::SHA2::Instantiations::SHA256 | ||
} |
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 |
---|---|---|
|
@@ -39,22 +39,18 @@ module Primitive::Asymmetric::Signature::ECDSA::Specification where | |
*/ | ||
import interface Common::EC::ECInterface as EC | ||
|
||
|
||
import Primitive::Asymmetric::Signature::ECDSA::UnconstrainedSpec | ||
{ interface EC } as USpec | ||
|
||
/** | ||
* ECDSA digital signature generation and verification requires an approved | ||
* hash function or XOF (extendable-output function). | ||
* This implementation currently fixes the hash function to SHA256, as | ||
* specified in [FIPS-180-4]. | ||
* | ||
* @design Marcella Hastings <[email protected]>. Fixing the hash function | ||
* to SHA256 is due to lack of an appropriate hash-function interface, not | ||
* for any technical reason. This is intended to be a temporary state, | ||
* blocked on the creation of such an interface. | ||
*/ | ||
import Primitive::Keyless::Hash::SHA2Imperative::SHA256 as Hash | ||
import interface Primitive::Keyless::Hash::HashInterface as Hash | ||
|
||
/** | ||
* The unconstrained spec is instantiated with the same curve and hash function | ||
* specified here. | ||
*/ | ||
import Primitive::Asymmetric::Signature::ECDSA::UnconstrainedSpec | ||
{ EC = interface EC , Hash = interface Hash } as USpec | ||
|
||
/** | ||
* The standard specifies four ranges for the bit length of `n` (the order of | ||
|
@@ -75,7 +71,7 @@ type ECSecurityStrength = (width EC::n / 2) | |
* security strength associated with the curve. | ||
* [FIPS-186-5] Section 6.1.1. | ||
*/ | ||
interface constraint (ECSecurityStrength <= Hash::securityStrength) | ||
interface constraint (ECSecurityStrength <= Hash::SecurityStrength) | ||
|
||
// Documentation for the public interface of this API can be found in | ||
// `UnconstrainedSpec.cry`. | ||
|
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ Test vectors for ECDSA with curve P256. | |
@copyright Galois, Inc. | ||
@author Marcella Hastings <[email protected]> | ||
*/ | ||
import Primitive::Asymmetric::Signature::ECDSA::Instantiations::ECDSA_P256 as ECDSA | ||
import Primitive::Asymmetric::Signature::ECDSA::Instantiations::ECDSA_P256_SHA256 as ECDSA | ||
import Common::utils(BVtoZ) | ||
|
||
/** | ||
|
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,42 @@ | ||
/* | ||
* Interface for a hash function with a fixed-length digest. | ||
* | ||
* This is designed for use in algorithms that require an arbitrary hash | ||
* function. It does not support extendable-output functions that allow | ||
* arbitrary-length outputs. | ||
* | ||
* @copyright Galois, Inc 2025 | ||
* @author Marcella Hastings <[email protected]> | ||
*/ | ||
interface module Primitive::Keyless::Hash::HashInterface where | ||
/** | ||
* Upper bound on the length of messages that can be hashed with this | ||
* hash function. | ||
* | ||
* This can be set to `inf` for hash functions that do not have a | ||
* restriction on message length. | ||
*/ | ||
type MessageUpperBound : # | ||
|
||
/** | ||
* Length of the hash digest, in bits. | ||
*/ | ||
type DigestLength : # | ||
|
||
/** | ||
* Security strength (in bits) of the hash function. | ||
* | ||
* This is assumed to be the minimum of the collision resistance strength, | ||
* the preimage resistance strength, and the second preimage resistance | ||
* strength. For most NIST-standardized hash functions, the security | ||
* strength is half the digest length. The exception is SHA-1, which is | ||
* largely deprecated. | ||
* @see https://csrc.nist.gov/projects/hash-functions#security-strengths | ||
*/ | ||
type SecurityStrength : # | ||
|
||
/** | ||
* Hash function, mapping an arbitrary-length message to a fixed-length | ||
* message digest. | ||
*/ | ||
hash: {m} (fin m, width m < MessageUpperBound) => [m] -> [DigestLength] |
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