openssl/crypto/ec/curve448/utils.c
Matt Caswell 7324473f89 Import Curve 448 support
This imports selected files from the src directory of this repository:

https://sourceforge.net/p/ed448goldilocks/code/ci/v0.9.4/tree/

This is from the version tagged as "v0.9.4" with commit id 7527e9.

This code was originally writting by Mike Hamburg and the import is done by
kind permission of Rambus and Mike Hamburg under CLA. As this is under CLA
the files are being relicensed under the OpenSSL licence. Subsequent
commits will correct any licence notices in the individual files.

These files should provide complete self-contained support for X448 and
Ed448. They are imported "as is" from the source repository and this
commit does not attempt to integrate them into the OpenSSL build system,
or modify them in any way to fit OpenSSL style guidelines. That will be
done by subsequent commits.

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/5105)
2018-02-20 12:59:29 +00:00

44 lines
1.1 KiB
C

/* Copyright (c) 2015 Cryptography Research, Inc.
* Released under the MIT License. See LICENSE.txt for license information.
*/
/**
* @file utils.c
* @author Mike Hamburg
* @brief Decaf utility functions.
*/
#include <decaf/common.h>
void decaf_bzero (
void *s,
size_t size
) {
#ifdef __STDC_LIB_EXT1__
memset_s(s, size, 0, size);
#else
const size_t sw = sizeof(decaf_word_t);
volatile uint8_t *destroy = (volatile uint8_t *)s;
for (; size && ((uintptr_t)destroy)%sw; size--, destroy++)
*destroy = 0;
for (; size >= sw; size -= sw, destroy += sw)
*(volatile decaf_word_t *)destroy = 0;
for (; size; size--, destroy++)
*destroy = 0;
#endif
}
decaf_bool_t decaf_memeq (
const void *data1_,
const void *data2_,
size_t size
) {
const unsigned char *data1 = (const unsigned char *)data1_;
const unsigned char *data2 = (const unsigned char *)data2_;
unsigned char ret = 0;
for (; size; size--, data1++, data2++) {
ret |= *data1 ^ *data2;
}
return (((decaf_dword_t)ret) - 1) >> 8;
}