Coder Social home page Coder Social logo

sha256_literal's Introduction

Header-only constexpr SHA256 C++ 14 literal

THis is a C++14 constexpr implementation of SHA256, which allows (among others) the usage of a "_sha256" literal to get compile-time SHA256 hashes:

#include "sha256_literal.h"

static constexpr sha256::HashType H = "mypassword"_sha256;
// HashType is a std::array<uint8_t, 32>

More "low-level" API are also provided:

static constexpr auto H0 = sha256::compute_str("hello");
static constexpr auto H1 = sha256::compute({'A','B'});

This can be used for instance to compare user-provided passwords to a hard-coded one in a binary (although this is not recommended to do so directly, passwords should always be salted when hashed!):

#include "sha256.h"
#include "sha256_literal.h"

bool isGoodPwd(const char* Pwd) {
  static constexpr auto PasswordHash = "myverysecretpassword"_sha256;
  return sha256::compute((const uint8_t*) Pwd, strlen(Pwd)) == PasswordHash;
}

See the tests.cpp file for tests, and the example.cpp for a usage example.

A runtime implementation of SHA256 is also provided in sha256.cpp. This does not respect the NIST API standards, and is only there for convience.

This has been tested with clang 4.0 and GCC 6.3 under linux.

Licensing

This code is licensed under GPLv3, except for the QBDI project (https://github.com/QBDI/QBDI/) that uses it for benchmarking purpose where we tolerate the usage of this code under the Apache2 license.

sha256_literal's People

Contributors

aguinet avatar aguinetqb avatar jwilk avatar nsurbay avatar stefanhamminga 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.