/**
* Initialize any derived fields in pv.
*/
-static inline void pv_init_extra(polyval_t *pv);
+static inline void pv_init_extra(polyval_key_t *pv);
/* ========
* The function which we expect our backend to implement.
pv->y = _mm_xor_si128(pv->y, v);
}
static inline void
-pv_init_extra(polyval_t *pv)
+pv_init_extra(polyval_key_t *pv)
{
(void)pv;
}
pv->y.hi ^= val.hi;
}
static inline void
-pv_init_extra(polyval_t *pv)
+pv_init_extra(polyval_key_t *pv)
{
pv->hr.lo = rev64(pv->h.lo);
pv->hr.hi = rev64(pv->h.hi);
}
}
static inline void
-pv_init_extra(polyval_t *pv)
+pv_init_extra(polyval_key_t *pv)
{
(void)pv;
}
#endif
+void
+polyval_key_init(polyval_key_t *pvk, const uint8_t *key)
+{
+ pvk->h = u128_from_bytes(key);
+ pv_init_extra(pvk);
+}
void
polyval_init(polyval_t *pv, const uint8_t *key)
{
- pv->h = u128_from_bytes(key);
+ polyval_key_init(&pv->key, key);
+ memset(&pv->y, 0, sizeof(u128));
+}
+void
+polyval_init_from_key(polyval_t *pv, const polyval_key_t *key)
+{
+ memcpy(&pv->key, key, sizeof(polyval_key_t));
memset(&pv->y, 0, sizeof(u128));
- pv_init_extra(pv);
}
void
polyval_add_block(polyval_t *pv, const uint8_t *block)
} pv_u128_;
#endif
-/**
- * State for an instance of the polyval hash.
- **/
-typedef struct polyval_t {
- /** The key itself. */
+/** A key for a polyval hash, plus any precomputed key material. */
+typedef struct polyval_key_t {
pv_u128_ h;
#ifdef PV_USE_CTMUL64
/** The elements of the key in bit-reversed form.
* (Used as an optimization.) */
pv_u128_ hr;
#endif
+} polyval_key_t;
+
+/**
+ * State for an instance of the polyval hash.
+ **/
+typedef struct polyval_t {
+ /** The key used for this instance of polyval. */
+ polyval_key_t key;
/** The accumulator */
pv_u128_ y;
} polyval_t;
*/
#define POLYVAL_TAG_LEN 16
+/** Do any necessary precomputation from a polyval key,
+ * and store it.
+ */
+void polyval_key_init(polyval_key_t *, const uint8_t *key);
/**
* Initialize a polyval instance with a given key.
*/
void polyval_init(polyval_t *, const uint8_t *key);
+/**
+ * Initialize a polyval instance with a preconstructed key.
+ */
+void polyval_init_from_key(polyval_t *, const polyval_key_t *key);
/**
* Update a polyval instance with a new 16-byte block.
*/