Code Monkey home page Code Monkey logo

mad-hmac's Introduction

About

mad-hmac is for HMAC-SHA1 and HMAC-SHA2 (224/256/364/512) calculation, it's small and self-contained without other dependencies.

Features

  • Small
  • Easy to use
  • Portable
  • Free

Usage

Three pairs of inputs:

  1. key: the key for hashing.

  2. message: the message to be hashed.

  3. hash: the hash output.

As the length of the hash are fixed values, for the hash_len, please use the macros, e.g., SHA1_DIGEST_SIZE.

#include "../src/hmac_sha1.h"
#include "../src/hmac_sha2.h"
#include <string.h>

int main() {

    uint32_t hash_len = SHA256_DIGEST_SIZE;
    uint8_t  hash[hash_len];

    const uint8_t *key     = "Never tell";
    uint32_t       key_len = strlen(key);

    const uint8_t *message     = "I'm your little secret";
    uint32_t       message_len = strlen(message);

    uint32_t i = 0;

    hmac_sha256(key, key_len, message, message_len, hash, hash_len);

    for (i = 0; i < hash_len; ++i) {
        printf("%x", hash[i]);
    }

    return 0;
}

The above code will output: 106dc44b4868798e5c55fd253249605e8c931282dc2f593eab7651af294c6.

License

  1. The SHA-1 implementation is from here. It's in public domain.

  2. The SHA-2 and HMAC-SHA2 are from here. It follows the new BSD license.

  3. My work of HMAC-SHA1 follows new BSD license.

mad-hmac's People

Contributors

madwyn avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.