Mercurial > hg > ucis.core
comparison NaCl/APIv2.cs @ 80:4714531734b3
NaCl: fixed signature bounds check
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Sun, 16 Feb 2014 15:05:31 +0100 |
parents | 6aca18ee4ec6 |
children |
comparison
equal
deleted
inserted
replaced
79:4e4c600031e2 | 80:4714531734b3 |
---|---|
1 using System; | 1 using System; |
2 using System.Globalization; | 2 using System.Globalization; |
3 using UCIS.Util; | 3 using UCIS.Util; |
4 using curve25519xsalsa20poly1305impl = UCIS.NaCl.crypto_box.curve25519xsalsa20poly1305; | 4 using curve25519xsalsa20poly1305impl = UCIS.NaCl.crypto_box.curve25519xsalsa20poly1305; |
5 using ed25519impl = UCIS.NaCl.crypto_sign.ed25519; | |
5 using edwards25519sha512batchimpl = UCIS.NaCl.crypto_sign.edwards25519sha512batch; | 6 using edwards25519sha512batchimpl = UCIS.NaCl.crypto_sign.edwards25519sha512batch; |
7 using sha512impl = UCIS.NaCl.crypto_hash.sha512; | |
6 using xsalsa20poly1305impl = UCIS.NaCl.crypto_secretbox.xsalsa20poly1305; | 8 using xsalsa20poly1305impl = UCIS.NaCl.crypto_secretbox.xsalsa20poly1305; |
7 using sha512impl = UCIS.NaCl.crypto_hash.sha512; | |
8 using ed25519impl = UCIS.NaCl.crypto_sign.ed25519; | |
9 | 9 |
10 namespace UCIS.NaCl.v2 { | 10 namespace UCIS.NaCl.v2 { |
11 public class curve25519keypair { | 11 public class curve25519keypair { |
12 private Byte[] secretkey; | 12 private Byte[] secretkey; |
13 private Byte[] publickey = null; | 13 private Byte[] publickey = null; |
324 if (signature.Length < 64) throw new ArgumentException("signature"); | 324 if (signature.Length < 64) throw new ArgumentException("signature"); |
325 if (pk.Length < 32) throw new ArgumentException("pk"); | 325 if (pk.Length < 32) throw new ArgumentException("pk"); |
326 fixed (Byte* sp = signature, mp = message, kp = pk) return ed25519impl.crypto_sign_verify(sp, mp, message.Length, kp); | 326 fixed (Byte* sp = signature, mp = message, kp = pk) return ed25519impl.crypto_sign_verify(sp, mp, message.Length, kp); |
327 } | 327 } |
328 public static unsafe Boolean VerifySignature(ArraySegment<Byte> message, ArraySegment<Byte> signature, Byte[] pk) { | 328 public static unsafe Boolean VerifySignature(ArraySegment<Byte> message, ArraySegment<Byte> signature, Byte[] pk) { |
329 if (signature.Offset < 0 || signature.Count < 64 || signature.Offset + signature.Count < signature.Array.Length) throw new ArgumentException("signature"); | 329 if (signature.Offset < 0 || signature.Count < 64 || signature.Offset + signature.Count > signature.Array.Length) throw new ArgumentException("signature"); |
330 if (message.Offset < 0 || message.Count < 0 || message.Offset + message.Count < message.Array.Length) throw new ArgumentException("message"); | 330 if (message.Offset < 0 || message.Count < 0 || message.Offset + message.Count > message.Array.Length) throw new ArgumentException("message"); |
331 if (pk.Length < 32) throw new ArgumentException("pk"); | 331 if (pk.Length < 32) throw new ArgumentException("pk"); |
332 fixed (Byte* sp = signature.Array, mp = message.Array, kp = pk) return ed25519impl.crypto_sign_verify(sp + signature.Offset, mp + message.Offset, message.Count, kp); | 332 fixed (Byte* sp = signature.Array, mp = message.Array, kp = pk) return ed25519impl.crypto_sign_verify(sp + signature.Offset, mp + message.Offset, message.Count, kp); |
333 } | 333 } |
334 public static unsafe Boolean VerifySignedMessage(Byte[] signedmessage, Byte[] pk) { | 334 public static unsafe Boolean VerifySignedMessage(Byte[] signedmessage, Byte[] pk) { |
335 if (signedmessage.Length < 64) throw new ArgumentException("signedmessage"); | 335 if (signedmessage.Length < 64) throw new ArgumentException("signedmessage"); |