progs/perftest.c: Use from Glibc syscall numbers.
[catacomb] / symm / salsa20.h
index 4a0d1eb..7f3059e 100644 (file)
@@ -5,6 +5,26 @@
  * (c) 2015 Straylight/Edgeware
  */
 
+/*----- Licensing notice --------------------------------------------------*
+ *
+ * This file is part of Catacomb.
+ *
+ * Catacomb is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * Catacomb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with Catacomb; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
 #ifndef CATACOMB_SALSA20_H
 #define CATACOMB_SALSA20_H
 
@@ -27,6 +47,7 @@
 /*----- Constants ---------------------------------------------------------*/
 
 #define SALSA20_NONCESZ 8u
+#define SALSA20_IETF_NONCESZ 12u
 #define SALSA20_KEYSZ 32u
 #define SALSA20_OUTSZ 64u
 
@@ -43,8 +64,8 @@ typedef uint32 salsa20_matrix[16];
 
 typedef struct salsa20_ctx {
   salsa20_matrix a;
-  octet buf[SALSA20_OUTSZ];
-  size_t bufi;
+  octet b[SALSA20_OUTSZ];
+  unsigned off;
 } salsa20_ctx;
 
 #define XSALSA20_DEFCTX(name)                                          \
@@ -71,10 +92,11 @@ extern void salsa20_init(salsa20_ctx */*ctx*/,
                         const void */*key*/, size_t /*ksz*/,
                         const void */*nonce*/);
 
-/* --- @salsa20_setnonce@ --- *
+/* --- @salsa20_setnonce{,_ietf}@ --- *
  *
  * Arguments:  @salsa20_ctx *ctx@ = pointer to context
- *             @const void *nonce@ = the nonce (@SALSA20_NONCESZ@ bytes)
+ *             @const void *nonce@ = the nonce (@SALSA20_NONCESZ@ or
+ *                     @SALSA20_IETF_NONCESZ@ bytes)
  *
  * Returns:    ---
  *
@@ -84,8 +106,10 @@ extern void salsa20_init(salsa20_ctx */*ctx*/,
  */
 
 extern void salsa20_setnonce(salsa20_ctx */*ctx*/, const void */*nonce*/);
+extern void salsa20_setnonce_ietf(salsa20_ctx */*ctx*/,
+                                 const void */*nonce*/);
 
-/* --- @salsa20_seek@, @salsa20_seeku64@ --- *
+/* --- @salsa20_seek{,u64,_ietf}@ --- *
  *
  * Arguments:  @salsa20_ctx *ctx@ = pointer to context
  *             @unsigned long i@, @kludge64 i@ = new position to set
@@ -100,8 +124,9 @@ extern void salsa20_setnonce(salsa20_ctx */*ctx*/, const void */*nonce*/);
 
 extern void salsa20_seek(salsa20_ctx */*ctx*/, unsigned long /*i*/);
 extern void salsa20_seeku64(salsa20_ctx */*ctx*/, kludge64 /*i*/);
+extern void salsa20_seek_ietf(salsa20_ctx */*ctx*/, uint32 /*i*/);
 
-/* --- @salsa20_tell@, @salsa20_tellu64@ --- *
+/* --- @salsa20_tell{,u64,_ietf}@ --- *
  *
  * Arguments:  @salsa20_ctx *ctx@ = pointer to context
  *
@@ -111,6 +136,7 @@ extern void salsa20_seeku64(salsa20_ctx */*ctx*/, kludge64 /*i*/);
 
 extern unsigned long salsa20_tell(salsa20_ctx */*ctx*/);
 extern kludge64 salsa20_tellu64(salsa20_ctx */*ctx*/);
+extern uint32 salsa20_tell_ietf(salsa20_ctx */*ctx*/);
 
 /* --- @salsa20{,12,8}_encrypt@ --- *
  *
@@ -284,21 +310,26 @@ extern void xsalsa208_encrypt(xsalsa208_ctx */*ctx*/,
 extern const octet salsa20_keysz[];
 #define salsa2012_keysz salsa20_keysz
 #define salsa208_keysz salsa20_keysz
+#define salsa20_ietf_keysz salsa20_keysz
+#define salsa2012_ietf_keysz salsa20_keysz
+#define salsa208_ietf_keysz salsa20_keysz
 #define xsalsa20_keysz salsa20_keysz
 #define xsalsa2012_keysz salsa20_keysz
 #define xsalsa208_keysz salsa20_keysz
 
-const gccipher salsa20, salsa2012, salsa208;
-const gccipher xsalsa20, xsalsa2012, xsalsa208;
+extern const gccipher salsa20, salsa2012, salsa208;
+extern const gccipher salsa20_ietf, salsa2012_ietf, salsa208_ietf;
+extern const gccipher xsalsa20, xsalsa2012, xsalsa208;
 
 /*----- Generic random number generator interface -------------------------*/
 
-/* --- @salsa20{,12,8}_rand@, @xsalsa20{,12,8}_rand@ --- *
+/* --- @salsa20{,12,8}{,_ietf}_rand@, @xsalsa20{,12,8}{,_ietf}_rand@ --- *
  *
  * Arguments:          @const void *k@ = pointer to key material
  *                     @size_t ksz@ = size of key material
  *                     @const void *n@ = pointer to nonce or null
- *                             (@SALSA20_NONCESZ@ or @XSALSA20_NONCESZ@)
+ *                             (@SALSA20_NONCESZ@, @SALSA20_IETF_NONCESZ@,
+ *                             or @XSALSA20_NONCESZ@)
  *
  * Returns:            Pointer to generic random number generator instance.
  *
@@ -312,6 +343,12 @@ extern grand *salsa2012_rand(const void */*k*/, size_t /*ksz*/,
                             const void */*n*/);
 extern grand *salsa208_rand(const void */*k*/, size_t /*ksz*/,
                            const void */*n*/);
+extern grand *salsa20_ietf_rand(const void */*k*/, size_t /*ksz*/,
+                               const void */*n*/);
+extern grand *salsa2012_ietf_rand(const void */*k*/, size_t /*ksz*/,
+                                 const void */*n*/);
+extern grand *salsa208_ietf_rand(const void */*k*/, size_t /*ksz*/,
+                                const void */*n*/);
 extern grand *xsalsa20_rand(const void */*k*/, size_t /*ksz*/,
                            const void */*n*/);
 extern grand *xsalsa2012_rand(const void */*k*/, size_t /*ksz*/,