changeset 80:4714531734b3

NaCl: fixed signature bounds check
author Ivo Smits <Ivo@UCIS.nl>
date Sun, 16 Feb 2014 15:05:31 +0100
parents 4e4c600031e2
children 3352f89cf6f5 0d389692be32
files NaCl/APIv2.cs Util/ArrayUtil.cs
diffstat 2 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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<Byte> message, ArraySegment<Byte> 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);
 		}
--- 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>(T[] input) {
 			return (T[])input.Clone();
 		}
+		public static T[] Convert<T>(IList input, Converter<Object, T> 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<T> ToList<T>(IEnumerable<T> input) {
 			return new List<T>(input);
 		}