# HG changeset patch # User Ivo Smits # Date 1392559531 -3600 # Node ID 4714531734b364e24928eaee22c94313acff2e7f # Parent 4e4c600031e27f5027375dda560235958c46fbac NaCl: fixed signature bounds check diff -r 4e4c600031e2 -r 4714531734b3 NaCl/APIv2.cs --- a/NaCl/APIv2.cs Sun Feb 16 15:02:36 2014 +0100 +++ b/NaCl/APIv2.cs Sun Feb 16 15:05:31 2014 +0100 @@ -2,10 +2,10 @@ using System.Globalization; using UCIS.Util; using curve25519xsalsa20poly1305impl = UCIS.NaCl.crypto_box.curve25519xsalsa20poly1305; +using ed25519impl = UCIS.NaCl.crypto_sign.ed25519; using edwards25519sha512batchimpl = UCIS.NaCl.crypto_sign.edwards25519sha512batch; +using sha512impl = UCIS.NaCl.crypto_hash.sha512; using xsalsa20poly1305impl = UCIS.NaCl.crypto_secretbox.xsalsa20poly1305; -using sha512impl = UCIS.NaCl.crypto_hash.sha512; -using ed25519impl = UCIS.NaCl.crypto_sign.ed25519; namespace UCIS.NaCl.v2 { public class curve25519keypair { @@ -326,8 +326,8 @@ fixed (Byte* sp = signature, mp = message, kp = pk) return ed25519impl.crypto_sign_verify(sp, mp, message.Length, kp); } public static unsafe Boolean VerifySignature(ArraySegment message, ArraySegment signature, Byte[] pk) { - if (signature.Offset < 0 || signature.Count < 64 || signature.Offset + signature.Count < signature.Array.Length) throw new ArgumentException("signature"); - if (message.Offset < 0 || message.Count < 0 || message.Offset + message.Count < message.Array.Length) throw new ArgumentException("message"); + if (signature.Offset < 0 || signature.Count < 64 || signature.Offset + signature.Count > signature.Array.Length) throw new ArgumentException("signature"); + if (message.Offset < 0 || message.Count < 0 || message.Offset + message.Count > message.Array.Length) throw new ArgumentException("message"); if (pk.Length < 32) throw new ArgumentException("pk"); fixed (Byte* sp = signature.Array, mp = message.Array, kp = pk) return ed25519impl.crypto_sign_verify(sp + signature.Offset, mp + message.Offset, message.Count, kp); } diff -r 4e4c600031e2 -r 4714531734b3 Util/ArrayUtil.cs --- a/Util/ArrayUtil.cs Sun Feb 16 15:02:36 2014 +0100 +++ b/Util/ArrayUtil.cs Sun Feb 16 15:05:31 2014 +0100 @@ -36,6 +36,11 @@ public static T[] ToArray(T[] input) { return (T[])input.Clone(); } + public static T[] Convert(IList input, Converter converter) { + T[] output = new T[input.Count]; + for (int i = 0; i < output.Length; i++) output[i] = converter(input[i]); + return output; + } public static IList ToList(IEnumerable input) { return new List(input); }