/** * Generate an identity key pair. Clients should only do this once, * at install time. * * @return the generated IdentityKeyPair. */ public static IdentityKeyPair GenerateIdentityKeyPair() { ECKeyPair keyPair = Curve.GenerateKeyPair(); IdentityKey publicKey = new IdentityKey(keyPair.GetPublicKey()); return(new IdentityKeyPair(publicKey, keyPair.GetPrivateKey())); }
public SignedPreKeyRecord(uint id, ulong timestamp, ECKeyPair keyPair, byte[] signature) { this.structure = SignedPreKeyRecordStructure.CreateBuilder() .SetId(id) .SetPublicKey(ByteString.CopyFrom(keyPair.GetPublicKey().Serialize())) .SetPrivateKey(ByteString.CopyFrom(keyPair.GetPrivateKey().Serialize())) .SetSignature(ByteString.CopyFrom(signature)) .SetTimestamp(timestamp) .Build(); }
public PreKeyRecord(uint id, ECKeyPair keyPair) { this.structure = PreKeyRecordStructure.CreateBuilder() .SetId(id) .SetPublicKey(ByteString.CopyFrom(keyPair.GetPublicKey() .Serialize())) .SetPrivateKey(ByteString.CopyFrom(keyPair.GetPrivateKey() .Serialize())) .Build(); }
public void SetSenderChain(ECKeyPair senderRatchetKeyPair, ChainKey chainKey) { Chain.Types.ChainKey chainKeyStructure = Chain.Types.ChainKey.CreateBuilder() .SetKey(ByteString.CopyFrom(chainKey.GetKey())) .SetIndex(chainKey.GetIndex()) .Build(); Chain senderChain = Chain.CreateBuilder() .SetSenderRatchetKey(ByteString.CopyFrom(senderRatchetKeyPair.GetPublicKey().Serialize())) .SetSenderRatchetKeyPrivate(ByteString.CopyFrom(senderRatchetKeyPair.GetPrivateKey().Serialize())) .SetChainKey(chainKeyStructure) .Build(); this.sessionStructure = this.sessionStructure.ToBuilder().SetSenderChain(senderChain).Build(); }
public void SetPendingKeyExchange(uint sequence, ECKeyPair ourBaseKey, ECKeyPair ourRatchetKey, IdentityKeyPair ourIdentityKey) { PendingKeyExchange structure = PendingKeyExchange.CreateBuilder() .SetSequence(sequence) .SetLocalBaseKey(ByteString.CopyFrom(ourBaseKey.GetPublicKey().Serialize())) .SetLocalBaseKeyPrivate(ByteString.CopyFrom(ourBaseKey.GetPrivateKey().Serialize())) .SetLocalRatchetKey(ByteString.CopyFrom(ourRatchetKey.GetPublicKey().Serialize())) .SetLocalRatchetKeyPrivate(ByteString.CopyFrom(ourRatchetKey.GetPrivateKey().Serialize())) .SetLocalIdentityKey(ByteString.CopyFrom(ourIdentityKey.GetPublicKey().Serialize())) .SetLocalIdentityKeyPrivate(ByteString.CopyFrom(ourIdentityKey.GetPrivateKey().Serialize())) .Build(); this.sessionStructure = this.sessionStructure.ToBuilder() .SetPendingKeyExchange(structure) .Build(); }
public SenderKeyState(uint id, uint iteration, byte[] chainKey, ECKeyPair signatureKey) : this(id, iteration, chainKey, signatureKey.GetPublicKey(), new May <ECPrivateKey>(signatureKey.GetPrivateKey())) { }
public Pair <RootKey, ChainKey> CreateChain(ECPublicKey theirRatchetKey, ECKeyPair ourRatchetKey) { byte[] sharedSecret = Curve.CalculateAgreement(theirRatchetKey, ourRatchetKey.GetPrivateKey()); byte[] derivedSecretBytes = kdf.DeriveSecrets(sharedSecret, key, Encoding.UTF8.GetBytes("WhisperRatchet"), DerivedRootSecrets.SIZE); DerivedRootSecrets derivedSecrets = new DerivedRootSecrets(derivedSecretBytes); RootKey newRootKey = new RootKey(kdf, derivedSecrets.GetRootKey()); ChainKey newChainKey = new ChainKey(kdf, derivedSecrets.GetChainKey(), 0); return(new Pair <RootKey, ChainKey>(newRootKey, newChainKey)); }