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

  • a3483c2
  • /
  • bikel3
  • /
  • m4f
  • /
  • cleanup.h
Raw File Download
Permalinks

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:4605e9686a1dca3127188a46e776d990abb5b6db
directory badge Iframe embedding
swh:1:dir:03923b55962c2e735997636bb556c266f41a3493
Citations

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 ...
cleanup.h
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0"
 *
 * Written by Nir Drucker, Shay Gueron and Dusan Kostic,
 * AWS Cryptographic Algorithms Group.
 *
 * Modification: 2021 Ming-Shing Chen, Tung Chou, and Markus Krausz
 *
 */

#pragma once

#include "utilities.h"

/* Runs _thecleanup function on _thealloc once _thealloc went out of scope */
#define DEFER_CLEANUP(_thealloc, _thecleanup) \
  __attribute__((cleanup(_thecleanup))) _thealloc

/* Create a cleanup function for pointers from function func, which accepts a
 * pointer. This is useful for DEFER_CLEANUP, as it passes &_thealloc into
 * _thecleanup function. This way,
 * if _thealloc is a pointer _thecleanup would receive a pointer to a
 * pointer.*/
#define DEFINE_POINTER_CLEANUP_FUNC(type, func) \
  static inline void func##_pointer((type)*p)   \
  {                                             \
    if(p && *p) {                               \
      func(*p);                                 \
    }                                           \
  }                                             \
  struct __useless_struct_to_allow_trailing_semicolon__

// len is bytes length of in
_INLINE_ void secure_clean(OUT uint8_t *p, IN const uint32_t len)
{
#if defined(_WIN32)
  SecureZeroMemory(p, len);
#else
  typedef void *(*memset_t)(void *, int, size_t);
  static volatile memset_t memset_func = bike_memset;
  memset_func(p, 0, len);
#endif
}

#define CLEANUP_FUNC(name, type)               \
  _INLINE_ void name##_cleanup(IN OUT type *o) \
  {                                            \
    secure_clean((uint8_t *)o, sizeof(*o));    \
  }

CLEANUP_FUNC(r, r_t)
CLEANUP_FUNC(m, m_t)
CLEANUP_FUNC(e, e_t)
CLEANUP_FUNC(sk, sk_t)
CLEANUP_FUNC(ss, ss_t)
CLEANUP_FUNC(ct, ct_t)
CLEANUP_FUNC(pad_r, pad_r_t)
CLEANUP_FUNC(pad_e, pad_e_t)
CLEANUP_FUNC(seed, seed_t)
CLEANUP_FUNC(syndrome, syndrome_t)
CLEANUP_FUNC(upc, upc_t)
CLEANUP_FUNC(func_k, func_k_t)
CLEANUP_FUNC(dbl_pad_r, dbl_pad_r_t)
CLEANUP_FUNC(quad_pad_r, quad_pad_r_t)

// The functions below require special handling because we deal
// with arrays and not structures.

_INLINE_ void compressed_idx_d_ar_cleanup(IN OUT compressed_idx_d_ar_t *o)
{
  for(int i = 0; i < N0; i++) {
    secure_clean((uint8_t *)&(*o)[i], sizeof((*o)[0]));
  }
}

_INLINE_ void seeds_cleanup(IN OUT seeds_t *o)
{
  for(int i = 0; i < NUM_OF_SEEDS; i++) {
    seed_cleanup(&(o->seed[i]));
  }
}

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— Contact— JavaScript license information— Web API

back to top