public class HawkSigner extends java.lang.Object implements MessageSigner
MessageSigner: initialise with a HawkPrivateKeyParameters
(optionally wrapped in ParametersWithRandom) for signing, or with a
HawkPublicKeyParameters for verification, then call
generateSignature(byte[]) / verifySignature(byte[], byte[]).
generateSignature(byte[]) returns the signature bytes only; the
NIST crypto_sign "signed message" form (msg || sig) is
reconstructed by callers when needed.
| Modifier and Type | Field and Description |
|---|---|
static int |
SG_MAX_HI_HAWK_1024 |
static int |
SG_MAX_HI_HAWK_256 |
static int |
SG_MAX_HI_HAWK_512 |
static int |
SG_MAX_LO_HAWK_1024 |
static int |
SG_MAX_LO_HAWK_256 |
static int |
SG_MAX_LO_HAWK_512 |
static short[] |
SIG_GAUSS_HI_HAWK_1024 |
static short[] |
SIG_GAUSS_HI_HAWK_256 |
static short[] |
SIG_GAUSS_HI_HAWK_512 |
static long[] |
SIG_GAUSS_LO_HAWK_1024 |
static long[] |
SIG_GAUSS_LO_HAWK_256 |
static long[] |
SIG_GAUSS_LO_HAWK_512 |
static int |
SIZE_128 |
static int |
SIZE_256 |
static int |
SIZE_512 |
static int |
SIZE_64 |
| Constructor and Description |
|---|
HawkSigner() |
| Modifier and Type | Method and Description |
|---|---|
static void |
basisM2Mul(int logn,
byte[] t0,
int t0Offset,
byte[] t1,
int t1Offset,
byte[] h0,
int h0Offset,
byte[] h1,
int h1Offset,
byte[] f2,
int f2Offset,
byte[] g2,
int g2Offset,
byte[] F2,
int F2Offset,
byte[] G2,
int G2Offset,
byte[] tmp,
int tmpOffset) |
static long |
bpMul32(int x,
int y)
Optimized binary polynomial multiplication of two 32-bit values in GF(2)
Returns 64-bit product (carry-less multiplication)
This implements the same "classic technique" as the C code using
the 4-way decomposition with masks
|
static void |
bpMuladd(int size,
byte[] d,
int dOffset,
byte[] a,
int aOffset,
byte[] b,
int bOffset,
byte[] tmp,
int tmpOffset)
Binary polynomial multiplication using Karatsuba algorithm
d += a * b (polynomial multiplication in GF(2))
|
static void |
bpMuladd128(byte[] d,
int dOffset,
byte[] a,
int aOffset,
byte[] b,
int bOffset,
byte[] tmp,
int tmpOffset) |
static void |
bpMuladd256(byte[] d,
int dOffset,
byte[] a,
int aOffset,
byte[] b,
int bOffset,
byte[] tmp,
int tmpOffset)
Binary polynomial multiplication and accumulation for 256-bit polynomials
Uses Karatsuba algorithm with 128-bit halves
|
static void |
bpMuladd512(byte[] d,
int dOffset,
byte[] a,
int aOffset,
byte[] b,
int bOffset,
byte[] tmp,
int tmpOffset)
Binary polynomial multiplication and accumulation for 512-bit polynomials
Uses Karatsuba algorithm with 256-bit halves
|
static void |
bpMuladd64(byte[] d,
int dOffset,
byte[] a,
int aOffset,
byte[] b,
int bOffset,
byte[] tmp,
int tmpOffset)
Binary polynomial multiplication and accumulation for 64-bit polynomials
d += a * b (polynomial multiplication in GF(2))
This is a direct translation of the C function that uses 32-bit halves
for efficient polynomial multiplication in GF(2)
|
static void |
bpXor128(byte[] d,
int dOffset,
byte[] a,
int aOffset,
byte[] b,
int bOffset) |
static void |
bpXor64(byte[] d,
int dOffset,
byte[] a,
int aOffset,
byte[] b,
int bOffset) |
int |
cryptoSign(byte[] sm,
long[] smlen,
byte[] m,
long mlen,
byte[] sk,
int logn)
Main signing function compatible with the crypto_sign API
|
static int |
dec16le(byte[] src,
int srcOffset) |
static int |
dec32le(byte[] src,
int srcOffset)
Decode 32-bit little-endian value from byte array
This is a direct translation of the C dec32le function
|
static long |
dec64le(byte[] src,
int srcOffset) |
static void |
enc32le(byte[] dst,
int dstOffset,
int x) |
static void |
enc64le(byte[] dst,
int dstOffset,
long x)
Encode 64-bit value as little-endian bytes
This is a direct translation of the C enc64le function
|
static boolean |
encodeSig(int logn,
byte[] sig,
int sigOffset,
int sigLen,
byte[] salt,
int saltOffset,
int saltLen,
short[] s1,
int s1Offset)
Encode the signature, with output length exactly sigLen bytes.
|
byte[] |
generateSignature(byte[] message)
sign the passed in message (usually the output of a hash function).
|
static org.bouncycastle.pqc.crypto.hawk.HawkSigner.GaussianTable |
getGaussianTable(int logn) |
static int |
getTmpSize(int polynomialSize) |
static int |
hawkPrivKeySize(int logn) |
int |
hawkSignFinish(int logn,
byte[] sig,
SHAKEDigest scData,
byte[] priv,
byte[] tmp,
int tmpLen) |
static SHAKEDigest |
hawkSignStart() |
static void |
hawkSignStart(SHAKEDigest sc)
Start the signing process - initialize SHAKE context
|
static int |
hawkSigSize(int logn) |
static int |
hawkTmpSizeSign(int logn) |
void |
init(boolean forSigning,
CipherParameters param)
initialise the signer for signature generation or signature
verification.
|
int |
mq18433Add(int x,
int y)
Modular addition: (x + y) mod Q, result in [1..Q] where Q represents 0 mod Q.
|
int |
mq18433Half(int x)
Compute half: x/2 mod Q.
|
int |
mq18433HalfMonty(int x)
Alternative half implementation using modular inverse of 2
|
void |
mq18433INTT(int logn,
short[] a,
int aOffset)
Inverse NTT matching C mq18433_iNTT exactly.
1/n normalization is embedded in the iGM twiddle factors.
|
void |
mq18433INTTWithScaling(int logn,
short[] a,
int aOffset)
Alias for mq18433INTT kept for compatibility.
|
int |
mq18433MontyMul(int x,
int y)
Montgomery multiplication: returns (x * y) mod Q in Montgomery form
|
int |
mq18433MontyRed(int x)
Montgomery reduction.
|
void |
mq18433NTT(int logn,
short[] a,
int aOffset)
Number Theoretic Transform (NTT) for modulus 18433
|
void |
mq18433NTTSafe(int logn,
short[] a,
int aOffset)
Alternative NTT implementation with explicit bounds checking
|
void |
mq18433PolySetSmall(int logn,
short[] d,
int dOffset,
byte[] a,
int aOffset)
Convert a small polynomial (signed 8-bit coefficients) to mod q representation.
|
void |
mq18433PolySetSmallBatch(int logn,
short[][] dArray,
int[] dOffsets,
byte[][] aArray,
int[] aOffsets)
Batch conversion for multiple polynomials
|
void |
mq18433PolySetSmallInplaceHigh(int logn,
short[] d,
int dOffset)
Convert a small polynomial (signed 8-bit coefficients) to a mod q
representation that _ends_ at the same address (i.e. the n last
bytes of d are read, and 2*n bytes are written into d).
|
void |
mq18433PolySetSmallInplaceLow(int logn,
short[] d,
int dOffset)
Convert a small polynomial in-place from packed bytes to mod q representation.
|
void |
mq18433PolySetSmallInplaceLowBatch(int logn,
short[][] dArray,
int[] dOffsets)
In-place conversion for multiple polynomials
|
static void |
mq18433PolySnorm(int logn,
short[] d,
int dOffset)
Apply signed normalization to polynomial coefficients
|
short |
mq18433SetSmall(byte x)
Convert a signed byte to a mod q value in the range [0, q-1]
This is the equivalent of Zq(set_small)
|
short |
mq18433SetSmallSafe(byte x)
Alternative implementation with bounds checking
|
static int |
mq18433Snorm(int x)
Signed normalization: convert to range [-floor((Q-1)/2), floor((Q-1)/2)].
|
static int |
mq18433SnormSafe(int x)
Alternative signed normalization with proper bounds
|
int |
mq18433Sub(int x,
int y)
Modular subtraction: (x - y) mod Q, result in [1..Q] where Q represents 0 mod Q.
|
int |
mq18433ToMonty(int x)
Convert a number to Montgomery form
|
static int |
polySymBreak(int logn,
short[] s,
int sOffset)
Returned value:
1 first non-zero coefficient of s is positive
-1 first non-zero coefficient of s is negative
0 s is entirely zero
|
static int |
polySymBreakExplicit(int logn,
short[] s,
int sOffset)
Alternative implementation with explicit sign detection
|
int |
sigGauss(int logn,
SHAKEDigest scExtra,
byte[] x,
int xOffset,
byte[] t,
int tOffset)
Generate x with the right Gaussian, for the specified parity bits.
|
int |
sigGaussAlt(int logn,
byte[] x,
int xOffset,
byte[] t,
int tOffset)
Alternate function for sampling x; the same mechanism is used, but the
provided RNG is used directly instead of instantiating four SHAKE
instances in parallel.
|
byte[] |
sign(byte[] message,
byte[] privateKey,
int logn)
Alternative signature with simpler Java-style API
|
int |
signFinishInner(int logn,
int useShake,
byte[] sig,
SHAKEDigest scData,
byte[] priv,
int privLen,
byte[] tmp,
int tmpLen) |
boolean |
verifySignature(byte[] message,
byte[] signature)
verify the message message against the signature value.
|
public static final short[] SIG_GAUSS_HI_HAWK_256
public static final int SG_MAX_HI_HAWK_256
public static final long[] SIG_GAUSS_LO_HAWK_256
public static final int SG_MAX_LO_HAWK_256
public static final short[] SIG_GAUSS_HI_HAWK_512
public static final int SG_MAX_HI_HAWK_512
public static final long[] SIG_GAUSS_LO_HAWK_512
public static final int SG_MAX_LO_HAWK_512
public static final short[] SIG_GAUSS_HI_HAWK_1024
public static final int SG_MAX_HI_HAWK_1024
public static final long[] SIG_GAUSS_LO_HAWK_1024
public static final int SG_MAX_LO_HAWK_1024
public static final int SIZE_64
public static final int SIZE_128
public static final int SIZE_256
public static final int SIZE_512
public void init(boolean forSigning,
CipherParameters param)
MessageSignerinit in interface MessageSignerforSigning - true if we are generating a signature, false
otherwise.param - key parameters for signature generation.public byte[] generateSignature(byte[] message)
MessageSignergenerateSignature in interface MessageSignermessage - the message to be signed.public boolean verifySignature(byte[] message,
byte[] signature)
MessageSignerverifySignature in interface MessageSignermessage - the message that was supposed to have been signed.signature - the signature of the messagepublic static SHAKEDigest hawkSignStart()
public int hawkSignFinish(int logn,
byte[] sig,
SHAKEDigest scData,
byte[] priv,
byte[] tmp,
int tmpLen)
public static void basisM2Mul(int logn,
byte[] t0,
int t0Offset,
byte[] t1,
int t1Offset,
byte[] h0,
int h0Offset,
byte[] h1,
int h1Offset,
byte[] f2,
int f2Offset,
byte[] g2,
int g2Offset,
byte[] F2,
int F2Offset,
byte[] G2,
int G2Offset,
byte[] tmp,
int tmpOffset)
public static void bpMuladd(int size,
byte[] d,
int dOffset,
byte[] a,
int aOffset,
byte[] b,
int bOffset,
byte[] tmp,
int tmpOffset)
public static void bpMuladd128(byte[] d,
int dOffset,
byte[] a,
int aOffset,
byte[] b,
int bOffset,
byte[] tmp,
int tmpOffset)
public static void bpXor64(byte[] d,
int dOffset,
byte[] a,
int aOffset,
byte[] b,
int bOffset)
public static void bpXor128(byte[] d,
int dOffset,
byte[] a,
int aOffset,
byte[] b,
int bOffset)
public static int getTmpSize(int polynomialSize)
public static void bpMuladd64(byte[] d,
int dOffset,
byte[] a,
int aOffset,
byte[] b,
int bOffset,
byte[] tmp,
int tmpOffset)
This is a direct translation of the C function that uses 32-bit halves for efficient polynomial multiplication in GF(2)
public static int dec32le(byte[] src,
int srcOffset)
public static long bpMul32(int x,
int y)
This implements the same "classic technique" as the C code using the 4-way decomposition with masks
public static void enc64le(byte[] dst,
int dstOffset,
long x)
public static void bpMuladd256(byte[] d,
int dOffset,
byte[] a,
int aOffset,
byte[] b,
int bOffset,
byte[] tmp,
int tmpOffset)
public static void bpMuladd512(byte[] d,
int dOffset,
byte[] a,
int aOffset,
byte[] b,
int bOffset,
byte[] tmp,
int tmpOffset)
public static void enc32le(byte[] dst,
int dstOffset,
int x)
public static long dec64le(byte[] src,
int srcOffset)
public static int dec16le(byte[] src,
int srcOffset)
public int sigGauss(int logn,
SHAKEDigest scExtra,
byte[] x,
int xOffset,
byte[] t,
int tOffset)
Returned value is the squared norm of x.
public static org.bouncycastle.pqc.crypto.hawk.HawkSigner.GaussianTable getGaussianTable(int logn)
public int sigGaussAlt(int logn,
byte[] x,
int xOffset,
byte[] t,
int tOffset)
Returned value is the squared norm of x.
public void mq18433PolySetSmall(int logn,
short[] d,
int dOffset,
byte[] a,
int aOffset)
public void mq18433PolySetSmallInplaceLow(int logn,
short[] d,
int dOffset)
The input is stored as packed bytes in the first n/2 elements of d, and the output is written as mod q values in all n elements of d.
public short mq18433SetSmall(byte x)
public short mq18433SetSmallSafe(byte x)
public void mq18433PolySetSmallBatch(int logn,
short[][] dArray,
int[] dOffsets,
byte[][] aArray,
int[] aOffsets)
public void mq18433PolySetSmallInplaceLowBatch(int logn,
short[][] dArray,
int[] dOffsets)
public void mq18433PolySetSmallInplaceHigh(int logn,
short[] d,
int dOffset)
public void mq18433NTT(int logn,
short[] a,
int aOffset)
public void mq18433NTTSafe(int logn,
short[] a,
int aOffset)
public int mq18433MontyMul(int x,
int y)
public int mq18433MontyRed(int x)
public int mq18433Add(int x,
int y)
d = Q-(x+y); d += Q & (d>>16); return Q-d;public int mq18433Sub(int x,
int y)
d = y-x; d += Q & (d>>16); return Q-d;public void mq18433INTT(int logn,
short[] a,
int aOffset)
public int mq18433ToMonty(int x)
public void mq18433INTTWithScaling(int logn,
short[] a,
int aOffset)
public int mq18433Half(int x)
public int mq18433HalfMonty(int x)
public static void mq18433PolySnorm(int logn,
short[] d,
int dOffset)
public static int mq18433Snorm(int x)
public static int mq18433SnormSafe(int x)
public static int polySymBreak(int logn,
short[] s,
int sOffset)
public static int polySymBreakExplicit(int logn,
short[] s,
int sOffset)
public static boolean encodeSig(int logn,
byte[] sig,
int sigOffset,
int sigLen,
byte[] salt,
int saltOffset,
int saltLen,
short[] s1,
int s1Offset)
public int signFinishInner(int logn,
int useShake,
byte[] sig,
SHAKEDigest scData,
byte[] priv,
int privLen,
byte[] tmp,
int tmpLen)
public int cryptoSign(byte[] sm,
long[] smlen,
byte[] m,
long mlen,
byte[] sk,
int logn)
public byte[] sign(byte[] message,
byte[] privateKey,
int logn)
public static void hawkSignStart(SHAKEDigest sc)
public static int hawkPrivKeySize(int logn)
public static int hawkSigSize(int logn)
public static int hawkTmpSizeSign(int logn)