summaryrefslogtreecommitdiffstats
path: root/contrib/libs/base64/plain32/enc_head.c
diff options
context:
space:
mode:
authorDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/libs/base64/plain32/enc_head.c
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/libs/base64/plain32/enc_head.c')
-rw-r--r--contrib/libs/base64/plain32/enc_head.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/contrib/libs/base64/plain32/enc_head.c b/contrib/libs/base64/plain32/enc_head.c
new file mode 100644
index 00000000000..451f1bdad0b
--- /dev/null
+++ b/contrib/libs/base64/plain32/enc_head.c
@@ -0,0 +1,23 @@
+// Assume that *out is large enough to contain the output.
+// Theoretically it should be 4/3 the length of src.
+const uint8_t *c = (const uint8_t *)src;
+uint8_t *o = (uint8_t *)out;
+
+// Use local temporaries to avoid cache thrashing:
+size_t outl = 0;
+struct plain32_base64_state st;
+st.bytes = state->bytes;
+st.carry = state->carry;
+
+// Turn three bytes into four 6-bit numbers:
+// in[0] = 00111111
+// in[1] = 00112222
+// in[2] = 00222233
+// in[3] = 00333333
+
+// Duff's device, a for() loop inside a switch() statement. Legal!
+switch (st.bytes)
+{
+ for (;;)
+ {
+ case 0: