progs/perftest.c: Use from Glibc syscall numbers.
[catacomb] / symm / chacha.h
index 419b19a..6c380dc 100644 (file)
@@ -47,6 +47,7 @@
 /*----- Constants ---------------------------------------------------------*/
 
 #define CHACHA_NONCESZ 8u
+#define CHACHA_IETF_NONCESZ 12u
 #define CHACHA_KEYSZ 32u
 #define CHACHA_OUTSZ 64u
 
@@ -63,8 +64,8 @@ typedef uint32 chacha_matrix[16];
 
 typedef struct chacha_ctx {
   chacha_matrix a;
-  octet buf[CHACHA_OUTSZ];
-  size_t bufi;
+  octet b[CHACHA_OUTSZ];
+  unsigned off;
 } chacha_ctx;
 
 #define XCHACHA_DEFCTX(name)                                           \
@@ -88,13 +89,14 @@ XCHACHA_DEFCTX(xchacha8_ctx);
  */
 
 extern void chacha_init(chacha_ctx */*ctx*/,
-                        const void */*key*/, size_t /*ksz*/,
-                        const void */*nonce*/);
+                       const void */*key*/, size_t /*ksz*/,
+                       const void */*nonce*/);
 
-/* --- @chacha_setnonce@ --- *
+/* --- @chacha_setnonce{,_ietf}@ --- *
  *
  * Arguments:  @chacha_ctx *ctx@ = pointer to context
- *             @const void *nonce@ = the nonce (@CHACHA_NONCESZ@ bytes)
+ *             @const void *nonce@ = the nonce (@CHACHA_NONCESZ@ or
+ *                     @CHACHA_IETF_NONCESZ@ bytes)
  *
  * Returns:    ---
  *
@@ -104,24 +106,26 @@ extern void chacha_init(chacha_ctx */*ctx*/,
  */
 
 extern void chacha_setnonce(chacha_ctx */*ctx*/, const void */*nonce*/);
+extern void chacha_setnonce_ietf(chacha_ctx */*ctx*/, const void */*nonce*/);
 
-/* --- @chacha_seek@, @chacha_seeku64@ --- *
+/* --- @chacha_seek{,u64,_ietf}@ --- *
  *
  * Arguments:  @chacha_ctx *ctx@ = pointer to context
- *             @unsigned long i@, @kludge64 i@ = new position to set
+ *             @unsigned long i@, @kludge64 i@, @uint32 i@ = new position
  *
  * Returns:    ---
  *
- * Use:                Sets a new stream position, in units of ChaCha output
+ * Use:                Sets a new stream position, in units of Chacha output
  *             blocks, which are @CHACHA_OUTSZ@ bytes each.  Byte
- *             granularity can be achieved by calling @chacha_encrypt@
+ *             granularity can be achieved by calling @chachaR_encrypt@
  *             appropriately.
  */
 
 extern void chacha_seek(chacha_ctx */*ctx*/, unsigned long /*i*/);
 extern void chacha_seeku64(chacha_ctx */*ctx*/, kludge64 /*i*/);
+extern void chacha_seek_ietf(chacha_ctx */*ctx*/, uint32 /*i*/);
 
-/* --- @chacha_tell@, @chacha_tellu64@ --- *
+/* --- @chacha_tell{,u64,_ietf}@ --- *
  *
  * Arguments:  @chacha_ctx *ctx@ = pointer to context
  *
@@ -131,6 +135,7 @@ extern void chacha_seeku64(chacha_ctx */*ctx*/, kludge64 /*i*/);
 
 extern unsigned long chacha_tell(chacha_ctx */*ctx*/);
 extern kludge64 chacha_tellu64(chacha_ctx */*ctx*/);
+extern uint32 chacha_tell_ietf(chacha_ctx */*ctx*/);
 
 /* --- @chacha{20,12,8}_encrypt@ --- *
  *
@@ -229,7 +234,7 @@ extern void xchacha12_setnonce(xchacha12_ctx */*ctx*/,
 extern void xchacha8_setnonce(xchacha8_ctx */*ctx*/,
                               const void */*nonce*/);
 
-/* --- @xchacha{20,12,8}_seek@, @xchacha{20,12,8}_seeku64@ --- *
+/* --- @xchacha{20,12,8}_seek{,u64}@ --- *
  *
  * Arguments:  @xchachaR_ctx *ctx@ = pointer to context
  *             @unsigned long i@, @kludge64 i@ = new position to set
@@ -253,7 +258,7 @@ extern void xchacha20_seeku64(xchacha20_ctx */*ctx*/, kludge64 /*i*/);
 extern void xchacha12_seeku64(xchacha12_ctx */*ctx*/, kludge64 /*i*/);
 extern void xchacha8_seeku64(xchacha8_ctx */*ctx*/, kludge64 /*i*/);
 
-/* --- @xchacha{20,12,8}_tell@, @xchacha{20,12,8}_tellu64@ --- *
+/* --- @xchacha{20,12,8}_tell{,u64}@ --- *
  *
  * Arguments:  @chacha_ctx *ctx@ = pointer to context
  *
@@ -305,22 +310,28 @@ extern const octet chacha_keysz[];
 #define chacha20_keysz chacha_keysz
 #define chacha12_keysz chacha_keysz
 #define chacha8_keysz chacha_keysz
+#define chacha_ietf_keysz chacha_keysz
+#define chacha20_ietf_keysz chacha_keysz
+#define chacha12_ietf_keysz chacha_keysz
+#define chacha8_ietf_keysz chacha_keysz
 #define xchacha_keysz chacha_keysz
 #define xchacha20_keysz chacha_keysz
 #define xchacha12_keysz chacha_keysz
 #define xchacha8_keysz chacha_keysz
 
-const gccipher chacha20, chacha12, chacha8;
-const gccipher xchacha20, xchacha12, xchacha8;
+extern const gccipher chacha20, chacha12, chacha8;
+extern const gccipher chacha20_ietf, chacha12_ietf, chacha8_ietf;
+extern const gccipher xchacha20, xchacha12, xchacha8;
 
 /*----- Generic random number generator interface -------------------------*/
 
-/* --- @chacha{20,12,8}_rand@, @xchacha{20,12,8}_rand@ --- *
+/* --- @chacha{20,12,8}{,_ietf}_rand@, @xchacha{20,12,8}_rand@ --- *
  *
  * Arguments:          @const void *k@ = pointer to key material
  *                     @size_t ksz@ = size of key material
  *                     @const void *n@ = pointer to nonce or null
- *                             (@CHACHA_NONCESZ@ or @XCHACHA_NONCESZ@)
+ *                             (@CHACHA_NONCESZ@, @CHACHA_IETF_NONCESZ@, or
+ *                             @XCHACHA_NONCESZ@)
  *
  * Returns:            Pointer to generic random number generator instance.
  *
@@ -334,6 +345,12 @@ extern grand *chacha12_rand(const void */*k*/, size_t /*ksz*/,
                            const void */*n*/);
 extern grand *chacha8_rand(const void */*k*/, size_t /*ksz*/,
                           const void */*n*/);
+extern grand *chacha20_ietf_rand(const void */*k*/, size_t /*ksz*/,
+                                const void */*n*/);
+extern grand *chacha12_ietf_rand(const void */*k*/, size_t /*ksz*/,
+                                const void */*n*/);
+extern grand *chacha8_ietf_rand(const void */*k*/, size_t /*ksz*/,
+                               const void */*n*/);
 extern grand *xchacha20_rand(const void */*k*/, size_t /*ksz*/,
                             const void */*n*/);
 extern grand *xchacha12_rand(const void */*k*/, size_t /*ksz*/,