]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: samples: add crc32c converter
authorEmmanuel Hocdet <manu@gandi.net>
Wed, 21 Mar 2018 10:19:01 +0000 (11:19 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 21 Mar 2018 15:17:00 +0000 (16:17 +0100)
This patch adds the support of CRC32c (rfc4960).

doc/configuration.txt
src/sample.c

index fc8304c8f6775644d477a3652ef5cafef6e891ab..43c91114cef2e20453903dd0fd4466efec360107 100644 (file)
@@ -12847,7 +12847,17 @@ crc32([<avalanche>])
   found in Ethernet, Gzip, PNG, etc... It is slower than the other algorithms
   but may provide a better or at least less predictable distribution. It must
   not be used for security purposes as a 32-bit hash is trivial to break. See
-  also "djb2", "sdbm", "wt6" and the "hash-type" directive.
+  also "djb2", "sdbm", "wt6", "crc32c" and the "hash-type" directive.
+
+crc32c([<avalanche>])
+  Hashes a binary input sample into an unsigned 32-bit quantity using the CRC32C
+  hash function. Optionally, it is possible to apply a full avalanche hash
+  function to the output if the optional <avalanche> argument equals 1. This
+  converter uses the same functions as described in RFC4960, Appendix B [8].
+  It is provided for compatibility with other software which want a CRC32C to be
+  computed on some input keys. It is slower than the other algorithms and it must
+  not be used for security purposes as a 32-bit hash is trivial to break. See
+  also "djb2", "sdbm", "wt6", "crc32" and the "hash-type" directive.
 
 da-csv-conv(<prop>[,<prop>*])
   Asks the DeviceAtlas converter to identify the User Agent string passed on
@@ -12890,8 +12900,8 @@ djb2([<avalanche>])
   balancing algorithms, so it will provide exactly the same results. It is
   mostly intended for debugging, but can be used as a stick-table entry to
   collect rough statistics. It must not be used for security purposes as a
-  32-bit hash is trivial to break. See also "crc32", "sdbm", "wt6" and the
-  "hash-type" directive.
+  32-bit hash is trivial to break. See also "crc32", "sdbm", "wt6", "crc32c",
+  and the "hash-type" directive.
 
 even
   Returns a boolean TRUE if the input value of type signed integer is even
@@ -13199,8 +13209,8 @@ sdbm([<avalanche>])
   balancing algorithms, so it will provide exactly the same results. It is
   mostly intended for debugging, but can be used as a stick-table entry to
   collect rough statistics. It must not be used for security purposes as a
-  32-bit hash is trivial to break. See also "crc32", "djb2", "wt6" and the
-  "hash-type" directive.
+  32-bit hash is trivial to break. See also "crc32", "djb2", "wt6", "crc32c",
+  and the "hash-type" directive.
 
 set-var(<var name>)
   Sets a variable with the input content and returns the content on the output
@@ -13442,8 +13452,8 @@ wt6([<avalanche>])
   balancing algorithms, so it will provide exactly the same results. It is
   mostly intended for debugging, but can be used as a stick-table entry to
   collect rough statistics. It must not be used for security purposes as a
-  32-bit hash is trivial to break. See also "crc32", "djb2", "sdbm", and the
-  "hash-type" directive.
+  32-bit hash is trivial to break. See also "crc32", "djb2", "sdbm", "crc32c",
+  and the "hash-type" directive.
 
 xor(<value>)
   Performs a bitwise "XOR" (exclusive OR) between <value> and the input value
index 3e1a156f0e9e4d9f5b9910cf0681d4f1803d7303..71ee59f0b92074a5bd79f9d7aaf9a70db55b58b2 100644 (file)
@@ -1743,6 +1743,16 @@ static int sample_conv_crc32(const struct arg *arg_p, struct sample *smp, void *
        return 1;
 }
 
+/* hashes the binary input into crc32c (RFC4960, Appendix B [8].) */
+static int sample_conv_crc32c(const struct arg *arg_p, struct sample *smp, void *private)
+{
+       smp->data.u.sint = hash_crc32c(smp->data.u.str.str, smp->data.u.str.len);
+       if (arg_p && arg_p->data.sint)
+               smp->data.u.sint = full_hash(smp->data.u.sint);
+       smp->data.type = SMP_T_SINT;
+       return 1;
+}
+
 /* This function escape special json characters. The returned string can be
  * safely set between two '"' and used as json string. The json string is
  * defined like this:
@@ -2910,6 +2920,7 @@ static struct sample_conv_kw_list sample_conv_kws = {ILH, {
        { "ltime",  sample_conv_ltime,     ARG2(1,STR,SINT), NULL, SMP_T_SINT, SMP_T_STR },
        { "utime",  sample_conv_utime,     ARG2(1,STR,SINT), NULL, SMP_T_SINT, SMP_T_STR },
        { "crc32",  sample_conv_crc32,     ARG1(0,SINT), NULL, SMP_T_BIN,  SMP_T_SINT  },
+       { "crc32c", sample_conv_crc32c,    ARG1(0,SINT), NULL, SMP_T_BIN,  SMP_T_SINT  },
        { "djb2",   sample_conv_djb2,      ARG1(0,SINT), NULL, SMP_T_BIN,  SMP_T_SINT  },
        { "sdbm",   sample_conv_sdbm,      ARG1(0,SINT), NULL, SMP_T_BIN,  SMP_T_SINT  },
        { "wt6",    sample_conv_wt6,       ARG1(0,SINT), NULL, SMP_T_BIN,  SMP_T_SINT  },