// SPDX-License-Identifier: GPL-2.0-or-later /* * Cryptographic API. * * Support for VIA PadLock hardware crypto engine. * * Copyright (c) 2006 Michal Ludvig <michal@logix.cz>
*/
/* Allocate a fallback and abort if it failed. */
fallback_tfm = crypto_alloc_ahash(fallback_driver_name, 0,
CRYPTO_ALG_NEED_FALLBACK |
CRYPTO_ALG_ASYNC); if (IS_ERR(fallback_tfm)) {
printk(KERN_WARNING PFX "Fallback driver '%s' could not be loaded!\n",
fallback_driver_name); return PTR_ERR(fallback_tfm);
}
if (crypto_shash_statesize(hash) !=
crypto_ahash_statesize(fallback_tfm)) {
crypto_free_ahash(fallback_tfm); return -EINVAL;
}
/* Add two shash_alg instance for hardware-implemented *
* multiple-parts hash supported by VIA Nano Processor.*/
staticint padlock_sha1_update_nano(struct shash_desc *desc, const u8 *src, unsignedint len)
{ /*The PHE require the out buffer must 128 bytes and 16-bytes aligned*/ struct sha1_state *state = padlock_shash_desc_ctx(desc); int blocks = len / SHA1_BLOCK_SIZE;
len -= blocks * SHA1_BLOCK_SIZE;
state->count += blocks * SHA1_BLOCK_SIZE;
/* Process the left bytes from the input data */ asmvolatile (".byte 0xf3,0x0f,0xa6,0xc8"
: "+S"(src), "+D"(state)
: "a"((long)-1), "c"((unsignedlong)blocks)); return len;
}
staticint padlock_sha256_update_nano(struct shash_desc *desc, const u8 *src, unsignedint len)
{ /*The PHE require the out buffer must 128 bytes and 16-bytes aligned*/ struct crypto_sha256_state *state = padlock_shash_desc_ctx(desc); int blocks = len / SHA256_BLOCK_SIZE;
len -= blocks * SHA256_BLOCK_SIZE;
state->count += blocks * SHA256_BLOCK_SIZE;
/* Process the left bytes from input data*/ asmvolatile (".byte 0xf3,0x0f,0xa6,0xd0"
: "+S"(src), "+D"(state)
: "a"((long)-1), "c"((unsignedlong)blocks)); return len;
}
if (!x86_match_cpu(padlock_sha_ids) || !boot_cpu_has(X86_FEATURE_PHE_EN)) return -ENODEV;
/* Register the newly added algorithm module if on *
* VIA Nano processor, or else just do as before */ if (c->x86_model < 0x0f) {
sha1 = &sha1_alg;
sha256 = &sha256_alg;
} else {
sha1 = &sha1_alg_nano;
sha256 = &sha256_alg_nano;
}
rc = crypto_register_shash(sha1); if (rc) goto out;
rc = crypto_register_shash(sha256); if (rc) goto out_unreg1;
printk(KERN_NOTICE PFX "Using VIA PadLock ACE for SHA1/SHA256 algorithms.\n");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.