public SenderKeyMessage(UInt32 keyId, UInt32 iteration, byte[] ciphertext, ECPrivateKey signatureKey) { byte[] version = { ByteUtil.IntsToByteHighAndLow(CURRENT_VERSION, CURRENT_VERSION) }; var messageObj = new WhisperProtos.SenderKeyMessage { id = (uint)keyId, iteration = (uint)iteration, ciphertext = ciphertext, }; byte[] message; using(var stream = new MemoryStream()) { Serializer.Serialize<WhisperProtos.SenderKeyMessage>(stream, messageObj); message = stream.ToArray(); } byte[] signature = GetSignature(signatureKey, ByteUtil.Combine(version, message)); _serialized = ByteUtil.Combine(version, message, signature); KeyId = keyId; Iteration = iteration; CipherText = ciphertext; }
public static byte[] CalculateSignature(ECPrivateKey privateKey, byte[] message) { if (privateKey.GetKeyType () == DJB_TYPE) { var sign = Sodium.SecretKeyAuth.SignHmacSha256 (message, privateKey.Serialize ()); return sign; } else { throw new Exception ("Unknown type"); } }
public static byte[] CalculateAgreement(ECPublicKey publicKey, ECPrivateKey privateKey) { if (publicKey.GetKeyType () != privateKey.GetKeyType ()) { throw new Exception ("Public and private keys must be of the same type!"); } if (publicKey.GetKeyType () == DJB_TYPE) { var sK = privateKey.Serialize (); var typedPK = publicKey.Serialize (); var pK = new byte[typedPK.Length - 1]; for (int i = 1; i < typedPK.Length; i++) { pK [i - 1] = typedPK [i]; } var shared = Sodium.ScalarMult.Mult (sK, pK); return shared; } else { throw new Exception ("Unknown type"); } }
private byte[] GetSignature(ECPrivateKey signatureKey, byte[] serialized) { try { return Curve.CalculateSignature(signatureKey, serialized); } catch(Exception e) { throw new InvalidOperationException("Assertion error: " + e); } }
public ECKeyPair(ECPrivateKey privateKey, ECPublicKey publicKey) { PrivateKey = privateKey; PublicKey = publicKey; }
public IdentityKeyPair(IdentityKey publicKey, ECPrivateKey privateKey) { PublicKey = publicKey; PrivateKey = privateKey; }