Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
content badge
swh:1:cnt:f21d85a9dd4c8f51070920b49de49c6ef1fb6b33

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
#ifndef SHA2_H
#define SHA2_H

#include <stddef.h>
#include <stdint.h>

/* The incremental API allows hashing of individual input blocks; these blocks
    must be exactly 64 bytes each.
    Use the 'finalize' functions for any remaining bytes (possibly over 64). */

/* Structure for the incremental API */
typedef struct {
    uint8_t ctx[40];
} sha224ctx;

/* Structure for the incremental API */
typedef struct {
    uint8_t ctx[40];
} sha256ctx;

/* Structure for the incremental API */
typedef struct {
    uint8_t ctx[72];
} sha384ctx;

/* Structure for the incremental API */
typedef struct {
    uint8_t ctx[72];
} sha512ctx;

/* ====== SHA224 API ==== */
/**
 * Initialize the incremental hashing API
 */
void sha224_inc_init(sha224ctx *state);

/**
 * Copy the hashing state
 */
void sha224_inc_ctx_clone(sha224ctx *stateout, const sha224ctx *statein);

/**
 * Absorb blocks
 */
void sha224_inc_blocks(sha224ctx *state, const uint8_t *in, size_t inblocks);

/**
 * Finalize and obtain the digest
 *
 * If applicable, this function will free the memory associated with the sha224ctx.
 */
void sha224_inc_finalize(uint8_t *out, sha224ctx *state, const uint8_t *in, size_t inlen);

/**
 * Destroy the state. Make sure to use this, as this API may not always be stack-based.
 */
void sha224_inc_ctx_release(sha224ctx *state);

/**
 * All-in-one sha224 function
 */
void sha224(uint8_t *out, const uint8_t *in, size_t inlen);

/* ====== SHA256 API ==== */

/**
 * Initialize the incremental hashing API
 */
void sha256_inc_init(sha256ctx *state);

/**
 * Copy the hashing state
 */
void sha256_inc_ctx_clone(sha256ctx *stateout, const sha256ctx *statein);

/**
 * Absorb blocks
 */
void sha256_inc_blocks(sha256ctx *state, const uint8_t *in, size_t inblocks);

/**
 * Finalize and obtain the digest
 *
 * If applicable, this function will free the memory associated with the sha256ctx.
 */
void sha256_inc_finalize(uint8_t *out, sha256ctx *state, const uint8_t *in, size_t inlen);

/**
 * Destroy the state. Make sure to use this, as this API may not always be stack-based.
 */
void sha256_inc_ctx_release(sha256ctx *state);


/**
 * All-in-one sha256 function
 */
void sha256(uint8_t *out, const uint8_t *in, size_t inlen);

/* ====== SHA384 API ==== */

/**
 * Initialize the incremental hashing API
 */
void sha384_inc_init(sha384ctx *state);

/**
 * Copy the hashing state
 */
void sha384_inc_ctx_clone(sha384ctx *stateout, const sha384ctx *statein);

/**
 * Absorb blocks
 */
void sha384_inc_blocks(sha384ctx *state, const uint8_t *in, size_t inblocks);

/**
 * Finalize and obtain the digest.
 *
 * If applicable, this function will free the memory associated with the sha384ctx.
 */
void sha384_inc_finalize(uint8_t *out, sha384ctx *state, const uint8_t *in, size_t inlen);

/**
 * Destroy the state. Make sure to use this if not calling finalize, as this API may not always be stack-based.
 */
void sha384_inc_ctx_release(sha384ctx *state);

/**
 * All-in-one sha384 function
 */
void sha384(uint8_t *out, const uint8_t *in, size_t inlen);


/* ====== SHA512 API ==== */

/**
 * Initialize the incremental hashing API
 */
void sha512_inc_init(sha512ctx *state);

/**
 * Copy the hashing state
 */
void sha512_inc_ctx_clone(sha512ctx *stateout, const sha512ctx *statein);

/**
 * Absorb blocks
 */
void sha512_inc_blocks(sha512ctx *state, const uint8_t *in, size_t inblocks);

/**
 * Finalize and obtain the digest
 *
 * If applicable, this function will free the memory associated with the sha512ctx.
 */
void sha512_inc_finalize(uint8_t *out, sha512ctx *state, const uint8_t *in, size_t inlen);

/**
 * Destroy the state. Make sure to use this if not calling finalize, as this API may not always be stack-based.
 */
void sha512_inc_ctx_release(sha512ctx *state);


/**
 * All-in-one sha512 function
 */
void sha512(uint8_t *out, const uint8_t *in, size_t inlen);

#endif

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API