Class SM9KeyExchange
Usage per party: construct with your own key-exchange private key (derived under
the KGC's published hid), the peer's identity, and whether you are the initiator (user A) or
responder (user B). Call generateEphemeral(SecureRandom) to produce your R value,
exchange R values, then call calculateKey(int, ECPoint) with the peer's R to obtain
the shared key. The optional key-confirmation tags are then available via
getResponderConfirmation() (S_B) and getInitiatorConfirmation()
(S_A), until a further generateEphemeral(SecureRandom) begins another exchange.
-
Constructor Summary
ConstructorsConstructorDescriptionSM9KeyExchange(SM9EncPrivateKeyParameters key, byte[] peerIdentity, boolean initiator) -
Method Summary
Modifier and TypeMethodDescriptionbyte[]calculateKey(int klenBits, ECPoint peerR) Compute the shared key ofklenBitsbits from the peer's ephemeral valuepeerR.generateEphemeral(SecureRandom random) Generate this party's ephemeral value R = [r]Q_peer (a G1 point) and retain the ephemeral scalar r.byte[]S_A = Hash(0x83 || g1 || Hash(g2||g3||IDA||IDB||RA||RB)): the confirmation the initiator sends to (and the responder checks against) the responder.byte[]S_B = Hash(0x82 || g1 || Hash(g2||g3||IDA||IDB||RA||RB)): the confirmation the responder sends to (and the initiator checks against) the initiator.
-
Constructor Details
-
SM9KeyExchange
-
-
Method Details
-
generateEphemeral
Generate this party's ephemeral value R = [r]Q_peer (a G1 point) and retain the ephemeral scalar r. Q_peer = [H1(peerIdentity||hid, N)]P1 + P_pub-e, using the hid this party's own key was derived under - both parties' keys come from the same KGC, which publishes the hid it chose. -
calculateKey
Compute the shared key ofklenBitsbits from the peer's ephemeral valuepeerR. Must be called aftergenerateEphemeral(SecureRandom).peerRmust be a point of SM9's own G1 - the curve is checked, not just the curve equation the point carries with it.The ephemeral answers exactly one peer value. GM/T 0044.3-2016 6.1 A2 and B2 draw a fresh r for each exchange, and one r combined with two peer values yields two shared keys the same party legitimately agrees on, so this call discards the ephemeral once it has derived a key: another exchange has to begin with a further
generateEphemeral(SecureRandom). The confirmation tags of the exchange just completed remain available. -
getResponderConfirmation
public byte[] getResponderConfirmation()S_B = Hash(0x82 || g1 || Hash(g2||g3||IDA||IDB||RA||RB)): the confirmation the responder sends to (and the initiator checks against) the initiator.The returned tag is a secret authenticator; a received value must be compared against it with
Arrays.constantTimeAreEqual(byte[], byte[]), notArrays.equals, to avoid a timing side channel. -
getInitiatorConfirmation
public byte[] getInitiatorConfirmation()S_A = Hash(0x83 || g1 || Hash(g2||g3||IDA||IDB||RA||RB)): the confirmation the initiator sends to (and the responder checks against) the responder.The returned tag is a secret authenticator; a received value must be compared against it with
Arrays.constantTimeAreEqual(byte[], byte[]), notArrays.equals, to avoid a timing side channel.
-