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

  • 85af370
  • /
  • common
  • /
  • keccaktest.c
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
  • directory
content badge Iframe embedding
swh:1:cnt:05d13381b7dfb3eb428157f3e5407e4a0a4579d2
directory badge Iframe embedding
swh:1:dir:1922c1a01549e34f1e57a20411522709569ca3d2

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
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
keccaktest.c
#include "randombytes.h"
#include <hal.h>
#include <fips202.h>
#include <sendfn.h>
#include <randombytes.h>
#include <string.h>

#include <stdio.h>


#include <stdio.h>
#include <string.h>

const unsigned char msg1[] = {
  0x84u, 0xb6u, 0x0cu, 0xb3u, 0x72u, 0x0bu, 0xf2u, 0x97u, 0x48u, 0x48u, 0x3cu, 0xf7u, 0xabu, 0xd0u, 0xd1u,
  0xf1u, 0xd9u, 0x38u, 0x04u, 0x59u, 0xdfu, 0xa9u, 0x68u, 0x46u, 0x0cu, 0x86u, 0xe5u, 0xd1u, 0xa5u, 0x4fu,
  0x0bu, 0x19u, 0xdau, 0xc6u, 0xa7u, 0x8bu, 0xf9u, 0x50u, 0x94u, 0x60u, 0xe2u, 0x9du, 0xd4u, 0x66u, 0xbbu,
  0x8bu, 0xdfu, 0x04u, 0xe5u, 0x48u, 0x3bu, 0x78u, 0x2eu, 0xb7u, 0x4du, 0x64u, 0x48u, 0x16u, 0x6fu, 0x89u,
  0x7au, 0xddu, 0x43u, 0xd2u, 0x95u, 0xe9u, 0x46u, 0x94u, 0x2au, 0xd9u, 0xa8u, 0x14u, 0xfau, 0xb9u, 0x5bu,
  0x4au, 0xaeu, 0xdeu, 0x6au, 0xe4u, 0xc8u, 0x10u, 0x8cu, 0x8eu, 0xdau, 0xefu, 0xf9u, 0x71u, 0xf5u, 0x8fu,
  0x7cu, 0xf9u, 0x65u, 0x66u, 0xc9u, 0xdcu, 0x9bu, 0x68u, 0x12u, 0x58u, 0x6bu, 0x70u, 0xd5u, 0xbcu, 0x78u,
  0xe2u, 0xf8u, 0x29u, 0xecu, 0x8eu, 0x17u, 0x9au, 0x6cu, 0xd8u, 0x1du, 0x22u, 0x4bu, 0x16u, 0x11u, 0x75u,
  0xfdu, 0x3au, 0x33u, 0xaau, 0xcfu, 0xb1u, 0x48u, 0x3fu,
};

const unsigned char md1[] = {
  0x88u, 0x14u, 0x63u, 0x0au, 0x39u, 0xdcu, 0xb9u, 0x97u, 0x92u, 0xccu, 0x4eu,
  0x08u, 0xcau, 0xe5u, 0xddu, 0x07u, 0x89u, 0x73u, 0xd1u, 0x5cu, 0xd1u, 0x9fu,
  0x17u, 0xbau, 0xcfu, 0x04u, 0xdeu, 0xdau, 0x9eu, 0x62u, 0xc4u, 0x5fu,
};

static int test(void)
{
  unsigned char buf[32];
  int r = 0;
  sha3_256(buf, msg1, sizeof(msg1));
  if(memcmp(buf, md1, sizeof(buf))) {
    hal_send_str("ERROR SHA3-256 output does not match test vector.\n");
    r = 1;
  }
  return r;
}

static int bench(void)
{
  char str[128];
  unsigned char msg[1024*32];
  unsigned char md[1024*32];
  uint64_t t0, t1;
#define TESTMD(MD) \
  hal_send_str("-"); \
  t0 = hal_get_time(); \
  MD(md, msg, sizeof(msg)); \
  t1 = hal_get_time(); \
  sprintf(str, #MD": %llu cycles", t1-t0); \
  hal_send_str(str)
  TESTMD(sha3_256);
  TESTMD(sha3_384);
  TESTMD(sha3_512);
#define TESTXOF(XOF) \
  hal_send_str("-"); \
  t0 = hal_get_time(); \
  XOF(md, sizeof(md), msg, sizeof(msg)); \
  t1 = hal_get_time(); \
  sprintf(str, #XOF": %llu cycles", t1-t0);     \
  hal_send_str(str)
  TESTXOF(shake128);
  TESTXOF(shake256);
  return 0;
}

int main(void)
{
  hal_setup(CLOCK_BENCHMARK);
  hal_send_str("===");
  if(test()){
    hal_send_str("ERR");
  } else {
    hal_send_str("ALL GOOD!");
  }
  bench();
  hal_send_str("###");
  return 0;
}

back to top

Software Heritage — Copyright (C) 2015–2025, 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