Path: blob/master/arch/x86/crypto/nhpoly1305-sse2-glue.c
26442 views
// SPDX-License-Identifier: GPL-2.01/*2* NHPoly1305 - ε-almost-∆-universal hash function for Adiantum3* (SSE2 accelerated version)4*5* Copyright 2018 Google LLC6*/78#include <crypto/internal/hash.h>9#include <crypto/internal/simd.h>10#include <crypto/nhpoly1305.h>11#include <linux/module.h>12#include <linux/sizes.h>13#include <asm/simd.h>1415asmlinkage void nh_sse2(const u32 *key, const u8 *message, size_t message_len,16__le64 hash[NH_NUM_PASSES]);1718static int nhpoly1305_sse2_update(struct shash_desc *desc,19const u8 *src, unsigned int srclen)20{21if (srclen < 64 || !crypto_simd_usable())22return crypto_nhpoly1305_update(desc, src, srclen);2324do {25unsigned int n = min_t(unsigned int, srclen, SZ_4K);2627kernel_fpu_begin();28crypto_nhpoly1305_update_helper(desc, src, n, nh_sse2);29kernel_fpu_end();30src += n;31srclen -= n;32} while (srclen);33return 0;34}3536static int nhpoly1305_sse2_digest(struct shash_desc *desc,37const u8 *src, unsigned int srclen, u8 *out)38{39return crypto_nhpoly1305_init(desc) ?:40nhpoly1305_sse2_update(desc, src, srclen) ?:41crypto_nhpoly1305_final(desc, out);42}4344static struct shash_alg nhpoly1305_alg = {45.base.cra_name = "nhpoly1305",46.base.cra_driver_name = "nhpoly1305-sse2",47.base.cra_priority = 200,48.base.cra_ctxsize = sizeof(struct nhpoly1305_key),49.base.cra_module = THIS_MODULE,50.digestsize = POLY1305_DIGEST_SIZE,51.init = crypto_nhpoly1305_init,52.update = nhpoly1305_sse2_update,53.final = crypto_nhpoly1305_final,54.digest = nhpoly1305_sse2_digest,55.setkey = crypto_nhpoly1305_setkey,56.descsize = sizeof(struct nhpoly1305_state),57};5859static int __init nhpoly1305_mod_init(void)60{61if (!boot_cpu_has(X86_FEATURE_XMM2))62return -ENODEV;6364return crypto_register_shash(&nhpoly1305_alg);65}6667static void __exit nhpoly1305_mod_exit(void)68{69crypto_unregister_shash(&nhpoly1305_alg);70}7172module_init(nhpoly1305_mod_init);73module_exit(nhpoly1305_mod_exit);7475MODULE_DESCRIPTION("NHPoly1305 ε-almost-∆-universal hash function (SSE2-accelerated)");76MODULE_LICENSE("GPL v2");77MODULE_AUTHOR("Eric Biggers <[email protected]>");78MODULE_ALIAS_CRYPTO("nhpoly1305");79MODULE_ALIAS_CRYPTO("nhpoly1305-sse2");808182