From 0158b2b1fdb6dd6419c4b773367404d116ca83b9 Mon Sep 17 00:00:00 2001
From: Frank Denis <github@pureftpd.org>
Date: Tue, 8 Mar 2016 09:32:37 +0100
Subject: [PATCH] Argon2: use negative error codes

---
 src/libsodium/crypto_pwhash/argon2/argon2.h | 74 ++++++++++-----------
 1 file changed, 35 insertions(+), 39 deletions(-)

diff --git a/src/libsodium/crypto_pwhash/argon2/argon2.h b/src/libsodium/crypto_pwhash/argon2/argon2.h
index b8688743..96070a17 100644
--- a/src/libsodium/crypto_pwhash/argon2/argon2.h
+++ b/src/libsodium/crypto_pwhash/argon2/argon2.h
@@ -73,65 +73,61 @@
 typedef enum Argon2_ErrorCodes {
     ARGON2_OK = 0,
 
-    ARGON2_OUTPUT_PTR_NULL = 1,
+    ARGON2_OUTPUT_PTR_NULL = -1,
 
-    ARGON2_OUTPUT_TOO_SHORT = 2,
-    ARGON2_OUTPUT_TOO_LONG = 3,
+    ARGON2_OUTPUT_TOO_SHORT = -2,
+    ARGON2_OUTPUT_TOO_LONG = -3,
 
-    ARGON2_PWD_TOO_SHORT = 4,
-    ARGON2_PWD_TOO_LONG = 5,
+    ARGON2_PWD_TOO_SHORT = -4,
+    ARGON2_PWD_TOO_LONG = -5,
 
-    ARGON2_SALT_TOO_SHORT = 6,
-    ARGON2_SALT_TOO_LONG = 7,
+    ARGON2_SALT_TOO_SHORT = -6,
+    ARGON2_SALT_TOO_LONG = -7,
 
-    ARGON2_AD_TOO_SHORT = 8,
-    ARGON2_AD_TOO_LONG = 9,
+    ARGON2_AD_TOO_SHORT = -8,
+    ARGON2_AD_TOO_LONG = -9,
 
-    ARGON2_SECRET_TOO_SHORT = 10,
-    ARGON2_SECRET_TOO_LONG = 11,
+    ARGON2_SECRET_TOO_SHORT = -10,
+    ARGON2_SECRET_TOO_LONG = -11,
 
-    ARGON2_TIME_TOO_SMALL = 12,
-    ARGON2_TIME_TOO_LARGE = 13,
+    ARGON2_TIME_TOO_SMALL = -12,
+    ARGON2_TIME_TOO_LARGE = -13,
 
-    ARGON2_MEMORY_TOO_LITTLE = 14,
-    ARGON2_MEMORY_TOO_MUCH = 15,
+    ARGON2_MEMORY_TOO_LITTLE = -14,
+    ARGON2_MEMORY_TOO_MUCH = -15,
 
-    ARGON2_LANES_TOO_FEW = 16,
-    ARGON2_LANES_TOO_MANY = 17,
+    ARGON2_LANES_TOO_FEW = -16,
+    ARGON2_LANES_TOO_MANY = -17,
 
-    ARGON2_PWD_PTR_MISMATCH = 18,    /* NULL ptr with non-zero length */
-    ARGON2_SALT_PTR_MISMATCH = 19,   /* NULL ptr with non-zero length */
-    ARGON2_SECRET_PTR_MISMATCH = 20, /* NULL ptr with non-zero length */
-    ARGON2_AD_PTR_MISMATCH = 21,     /* NULL ptr with non-zero length */
+    ARGON2_PWD_PTR_MISMATCH = -18,    /* NULL ptr with non-zero length */
+    ARGON2_SALT_PTR_MISMATCH = -19,   /* NULL ptr with non-zero length */
+    ARGON2_SECRET_PTR_MISMATCH = -20, /* NULL ptr with non-zero length */
+    ARGON2_AD_PTR_MISMATCH = -21,     /* NULL ptr with non-zero length */
 
-    ARGON2_MEMORY_ALLOCATION_ERROR = 22,
+    ARGON2_MEMORY_ALLOCATION_ERROR = -22,
 
-    ARGON2_FREE_MEMORY_CBK_NULL = 23,
-    ARGON2_ALLOCATE_MEMORY_CBK_NULL = 24,
+    ARGON2_FREE_MEMORY_CBK_NULL = -23,
+    ARGON2_ALLOCATE_MEMORY_CBK_NULL = -24,
 
-    ARGON2_INCORRECT_PARAMETER = 25,
-    ARGON2_INCORRECT_TYPE = 26,
+    ARGON2_INCORRECT_PARAMETER = -25,
+    ARGON2_INCORRECT_TYPE = -26,
 
-    ARGON2_OUT_PTR_MISMATCH = 27,
+    ARGON2_OUT_PTR_MISMATCH = -27,
 
-    ARGON2_THREADS_TOO_FEW = 28,
-    ARGON2_THREADS_TOO_MANY = 29,
+    ARGON2_THREADS_TOO_FEW = -28,
+    ARGON2_THREADS_TOO_MANY = -29,
 
-    ARGON2_MISSING_ARGS = 30,
+    ARGON2_MISSING_ARGS = -30,
 
-    ARGON2_ENCODING_FAIL = 31,
+    ARGON2_ENCODING_FAIL = -31,
 
-    ARGON2_DECODING_FAIL = 32,
+    ARGON2_DECODING_FAIL = -32,
 
-    ARGON2_THREAD_FAIL = 33,
+    ARGON2_THREAD_FAIL = -33,
 
-    ARGON2_DECODING_LENGTH_FAIL = 34,
+    ARGON2_DECODING_LENGTH_FAIL = -34,
 
-    ARGON2_VERIFY_MISMATCH = 35,
-
-    ARGON2_ERROR_CODES_LENGTH /* Do NOT remove; Do NOT add error codes after
-                                 this
-                                 error code */
+    ARGON2_VERIFY_MISMATCH = -35
 } argon2_error_codes;
 
 /* Argon2 external data structures */