Class SM9Engine
SM9Engine.Mode.STREAM) and SM4 in ECB mode with PKCS#7 padding
(SM9Engine.Mode.SM4). The ciphertext is C = C1 || C3 || C2, where C1 is the
G1 point [r]Q_B encoded as x||y, C3 = MAC(K2, C2), and C2 is the encapsulated
message.
Usage follows the SM2Engine pattern: construct with the desired mode,
init(true, new ParametersWithRandom(recipientKey, random)) to encrypt or
init(false, userKey) to decrypt, then processBlock(byte[], int, int).
The mode is the caller's to keep: C1 || C3 || C2 does not record which method produced it, so a ciphertext has to be decrypted by an engine constructed for the mode it was encrypted in. Neither mode produces or accepts a 16-byte C2: the stream mode refuses a 16-byte message, the SM4 mode a message of fewer than 16 bytes, which pads to one block, and both refuse a 16-byte C2 on decryption. A message of fewer than 16 bytes has to be sent in stream mode, and one of exactly 16 bytes in SM4 mode.
Usage warning: an identity's encryption key should be used for this algorithm
or for the KEM (SM9KEMExtractor), but not for
both. A deployment needing both has its KGC publish a separate hid for each function,
as it already does for the key exchange, so that the two keys are distinct. init(boolean, CipherParameters) also
refuses for decryption a key declared for the KEM, and one that has been used
for it - see SM9EncPrivateKeyParameters.recordUsage(int).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe GM/T 0044.4-2016 data-encapsulation method. -
Constructor Summary
ConstructorsConstructorDescriptionBase constructor: SM4 data encapsulation (SM9Engine.Mode.SM4).SM9Engine(SM9Engine.Mode mode) -
Method Summary
Modifier and TypeMethodDescriptionintgetOutputSize(int inputLen) Return an upper bound for the output produced byprocessBlock(byte[], int, int)oninputLeninput bytes (exact for encryption and stream-mode decryption, an upper bound for SM4-mode decryption, whose padding length is unknown until removed).voidinit(boolean forEncryption, CipherParameters param) Initialise the engine.byte[]processBlock(byte[] in, int inOff, int inLen)
-
Constructor Details
-
SM9Engine
public SM9Engine()Base constructor: SM4 data encapsulation (SM9Engine.Mode.SM4). -
SM9Engine
-
-
Method Details
-
init
Initialise the engine. For encryption pass the recipient'sSM9EncPublicKeyParameters, optionally wrapped in aParametersWithRandom; for decryption pass the user'sSM9EncPrivateKeyParameters. A recipient key formed underSM9EncMasterPrivateKeyParameters.HID_EXCHANGE, or a key-exchange user key, is refused: both belong to the key exchange, not to encryption. -
getOutputSize
public int getOutputSize(int inputLen) Return an upper bound for the output produced byprocessBlock(byte[], int, int)oninputLeninput bytes (exact for encryption and stream-mode decryption, an upper bound for SM4-mode decryption, whose padding length is unknown until removed). -
processBlock
- Throws:
InvalidCipherTextException
-