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;
}
时间: 2024-10-04 04:18:00

kernel crypto hmac sha256 API call code的相关文章

各种语言HMAC SHA256实现

语言包含:  Javascript ,PHP,Java,Groovy,C#,Objective C,Go,Ruby,Python,Perl,Dart,Swift,Rust,Powershell. Javascript HMAC SHA256 Run the code online with this jsfiddle. Dependent upon an open source js library calledhttp://code.google.com/p/crypto-js/. <scri

Linux Kernel Module(LKM) Init、Delete Code Principle Learning

目录 1. Linux模块(LKM)简介 2. 使用Linux模块 3. LKM模块加载原理 4. LKM模块卸载原理 1. Linux模块(LKM)简介 模块是一种向linux内核添加"设备驱动程序"."文件系统"."其他组件"的有效方法,而无须重新编译内核或重启系统,这消除了许多限制,同时带来了很多的优点 1. 通过使用模块,内核程序员能够预先编译大量驱动程序,而不会致使内核映像的尺寸发生膨胀.在自动检测硬件或用户提示后,安装例程会选择适当的

android 百度定位 api error code 大全

http://www.zhuke.com/user/zkuser33038828?GTI=baidu.com&m3=&lvhttp://www.zhuke.com/user/zkuser90921642?GTI=baidu.com&m3=&lvhttp://www.zhuke.com/user/zkuser36771367?GTI=baidu.com&m3=&lvhttp://www.zhuke.com/user/zkuser80244229?GTI=bai

1.Relationship in Entity Framework Using Code First Approach With Fluent API【使用EF Code-First方式和Fluent API来探讨EF中的关系】

In this article, you will learn about relationships in Entity Framework using the Code First Approach with Fluent API. 在这篇文章中,你将会学习到使用EF Code-First方式和Fluent API来探讨EF中的关系(一对一,一对多,多对多). Introduction[介绍] A relationship, in the context of databases, is a

nodejs api 中文文档

文档首页 英文版文档 本作品采用知识共享署名-非商业性使用 3.0 未本地化版本许可协议进行许可. Node.js v0.10.18 手册 & 文档 索引 | 在单一页面中浏览 | JSON格式 目录 关于本文档 稳定度 JSON 输出 概述 全局对象 global process console 类: Buffer require() require.resolve() require.cache require.extensions __filename __dirname module e

Windows Kernel Security Training Courses

http://www.codemachine.com/courses.html#kerdbg Windows Kernel Internals for Security Researchers This course takes a deep dive into the internals of the Windows kernel from a security perspective. Attendees learn about behind the scenes working of va

microblog actionscript API

package com.sina.microblog { import com.adobe.crypto.HMAC; import com.adobe.crypto.SHA1; import com.dynamicflash.util.Base64; import com.sina.microblog.data.MicroBlogComment; import com.sina.microblog.data.MicroBlogCount; import com.sina.microblog.da

HMAC加密的消息摘要码

HMAC(Hash Message Authentication Code)哈希消息授权码,它在消息摘要算法(例如MD5,SHA系列算法)的基础上,使用密钥对消息摘要进行加密.它相当于一个马甲,内里可以使用MD5,SHA1,SHA256,SHA384,SHA512等Message Digest算法,在生成的消息摘要的基础上再多一道加密的工序.所以HMAC包括,HmacMD5,HmacSHA1,HmacSHA384,HmacSHA512等种类.正是因为HMAC只是一个马甲,它才有了很大的灵活性,底

Kernel logging: APIs and implementation

Kernel API Logging within the kernel is performed using the printk function int printk( const char * fmt, ... ); The kernel code simply defines the log level as the first argument of the message, as illustrated in the following example for a critical