libskarnet
skalibs
Software
skarnet.org

The stdcrypto library interface

stdcrypto is a small collection of standard, public-domain cryptographic primitives. Currently, the following operations are provided:

Please bear in mind that sha1 is practically broken. Do not use it in security-critical applications.

Compiling

Programming

You should refer to the skalibs/stdcrypto.h header and included headers for the exact function prototypes.

SHA1

  SHA1Schedule ctx ;
  char const *message ;
  size_t messagelen ;
  unsigned char digest[20] ;

  sha1_init(&ctx) ;
  sha1_update(&ctx, message, messagelen) ;
  sha1_final(&ctx, digest) ;

SHA256

  SHA256Schedule ctx ;
  char const *message ;
  size_t messagelen ;
  char digest[32] ;

  sha256_init(&ctx) ;
  sha256_update(&ctx, message, messagelen) ;
  sha256_final(&ctx, digest) ;

SHA512

  SHA512Schedule ctx ;
  char const *message ;
  size_t messagelen ;
  char digest[64] ;

  sha512_init(&ctx) ;
  sha512_update(&ctx, message, messagelen) ;
  sha512_final(&ctx, digest) ;

blake2s

Same scheme as with the other hashes.
  blake2s_ctx ctx ;
  char const *message ;
  size_t messagelen ;
  size_t outlen = 32 ;  /* the user gives the length of the digest */
  char digest[outlen] ;

  blake2s_init(&ctx, outlen) ;
  blake2s_update(&ctx, message, messagelen) ;
  blake2s_final(&ctx, digest) ;

crc32c

This isn't a cryptography primitive, but just a function to compute the Castagnoli version of a cyclic redundancy code.
  uint32_t crc = 0 ;  /* no need for context except that crc needs to be initialized to 0 */
  char const *message ;
  size_t messagelen ;

  crc = crc32c(crc, message, messagelen) ;