kernel crypto hmac sha256 API call code

static int hmac_sha256(char *plaintext, unsigned int plain_text_size, char *key, unsigned int key_size, uint8_t *result){struct scatterlist sg;  struct crypto_hash *tfm;struct hash_desc desc;int ret;if (!result) {printk(KERN_ERR "param err\n");return -EINVAL;}tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);if (IS_ERR(tfm)) {printk(KERN_ERR "crypto_alloc_ahash failed: err %ld", PTR_ERR(tfm)); return -EINVAL;}desc.tfm = tfm;desc.flags = 0;sg_set_buf(&sg, plaintext, plain_text_size);ret = crypto_hash_setkey(tfm, key, key_size);if (ret) { printk(KERN_ERR "crypto_ahash_setkey failed: err %d", ret);goto out;}ret = crypto_hash_digest(&desc, &sg, plain_text_size, result); if(ret) {printk(KERN_ERR "digest() failed ret = %d\n", ret); goto out;}printk(KERN_DEBUG, "crypto hash digest size %d\n", crypto_hash_digestsize(tfm));out:crypto_free_hash(tfm);return -EINVAL;}

,近朱者赤,近墨者黑

kernel crypto hmac sha256 API call code

相关文章:

你感兴趣的文章:

标签云: