Bouncy Castle Cryptography Library 1.87

org.bouncycastle.crypto.generators
Class SM9Sm3

java.lang.Object
  extended byorg.bouncycastle.crypto.generators.SM9Sm3

public class SM9Sm3
extends java.lang.Object

The shared SM3-based auxiliary functions of SM9 (GM/T 0044-2016): the cryptographic functions H1 and H2 that map a byte string to an integer in [1, n-1] (GM/T 0044.2, 5.4), and the key derivation function KDF (GM/T 0044.3/0044.4). H_v is SM3 (256-bit output).


Method Summary
static java.math.BigInteger h1(byte[] z, java.math.BigInteger n)
          H1(Z, n): hash-to-range with the 0x01 domain prefix (GM/T 0044.2 5.4.2.2).
static java.math.BigInteger h2(byte[] z, java.math.BigInteger n)
          Deprecated. H2 is used only in signing and verification, which SM9Signer now does without this method, hashing the message as it is given rather than taking M || w in one array.
static byte[] kdf(byte[] z, int klenBits)
          The SM9 key derivation function KDF(Z, klen) (GM/T 0044.3/0044.4), a counter-mode construction over SM3 with a 32-bit big-endian counter starting at 1.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

h1

public static java.math.BigInteger h1(byte[] z,
                                      java.math.BigInteger n)
H1(Z, n): hash-to-range with the 0x01 domain prefix (GM/T 0044.2 5.4.2.2). The result is in [1, n-1], so n must be at least 2.


h2

public static java.math.BigInteger h2(byte[] z,
                                      java.math.BigInteger n)
Deprecated. H2 is used only in signing and verification, which SM9Signer now does without this method, hashing the message as it is given rather than taking M || w in one array.

H2(Z, n): hash-to-range with the 0x02 domain prefix (GM/T 0044.2 5.4.2.3). The result is in [1, n-1], so n must be at least 2.


kdf

public static byte[] kdf(byte[] z,
                         int klenBits)
The SM9 key derivation function KDF(Z, klen) (GM/T 0044.3/0044.4), a counter-mode construction over SM3 with a 32-bit big-endian counter starting at 1. is the requested output length in bits, and must be a positive whole number of bytes.

The standard defines the function for any klen, but the output here is a byte array, so a request that is not a whole number of bytes could only be answered by rounding - and rounding up hands back more bits than were asked for while rounding down hands back fewer, silently. A non-positive length has no output at all and used to raise NegativeArraySizeException from the buffer sizing for some negative values. Every in-tree caller passes a positive whole number of bytes.


Bouncy Castle Cryptography Library 1.87