Skip to content

Commit

Permalink
avoid STDVEC_DATAPTR
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Apr 24, 2024
1 parent ab4c8f1 commit 6a631c8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Fast and memory-efficient streaming hash functions. Performs direct hashing of s

Implementations include the SHA-256, SHA-3 and Keccak cryptographic hash functions, SHAKE256 extendable-output function (XOF), and 'SipHash' pseudo-random function.

The SHA-3 Secure Hash Standard was published by the National Institute of Standards and Technology (NIST) in 2015 at [doi:10.6028/NIST.FIPS.202](https://dx.doi.org/10.6028/NIST.FIPS.202). The SHA-256 Secure Hash Standard was published by NIST in 2002 at <https://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf>. The SipHash family of pseudo-random functions by Jean-Philippe Aumasson and Daniel J. Bernstein was published in 2012 at <https://ia.cr/2012/351>.<sup>[1]</sup>
The SHA-3 Secure Hash Standard was published by the National Institute of Standards and Technology (NIST) in 2015 at [doi:10.6028/NIST.FIPS.202](https://dx.doi.org/10.6028/NIST.FIPS.202). SHA-3 is based on the Keccak algorithm, designed by G. Bertoni, J. Daemen, M. Peeters and G. Van Assche. The SHA-256 Secure Hash Standard was published by NIST in 2002 at <https://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf>. The SipHash family of pseudo-random functions by Jean-Philippe Aumasson and Daniel J. Bernstein was published in 2012 at <https://ia.cr/2012/351>.<sup>[1]</sup>

The SHA-256 and SHA-3 implementations are based on those by the 'Mbed TLS' Trusted Firmware Project at <https://www.trustedfirmware.org/projects/mbed-tls>. The SipHash implementation is based on that of Daniele Nicolodi, David Rheinsberg and Tom Gundersen at <https://github.com/c-util/c-siphash>, which is in turn based on the reference implementation by Jean-Philippe Aumasson and Daniel J. Bernstein released to the public domain at <https://github.com/veorq/SipHash>.
The SHA-256, SHA-3 and Keccak implementations are based on those by the 'Mbed TLS' Trusted Firmware Project at <https://www.trustedfirmware.org/projects/mbed-tls>. The SipHash implementation is based on that of Daniele Nicolodi, David Rheinsberg and Tom Gundersen at <https://github.com/c-util/c-siphash>, which is in turn based on the reference implementation by Jean-Philippe Aumasson and Daniel J. Bernstein released to the public domain at <https://github.com/veorq/SipHash>.

### Installation

Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ pseudo-random function.
The SHA-3 Secure Hash Standard was published by the National Institute
of Standards and Technology (NIST) in 2015 at
[doi:10.6028/NIST.FIPS.202](https://dx.doi.org/10.6028/NIST.FIPS.202).
The SHA-256 Secure Hash Standard was published by NIST in 2002 at
SHA-3 is based on the Keccak algorithm, designed by G. Bertoni, J.
Daemen, M. Peeters and G. Van Assche. The SHA-256 Secure Hash Standard
was published by NIST in 2002 at
<https://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf>. The
SipHash family of pseudo-random functions by Jean-Philippe Aumasson and
Daniel J. Bernstein was published in 2012 at
<https://ia.cr/2012/351>.<sup>\[1\]</sup>

The SHA-256 and SHA-3 implementations are based on those by the ‘Mbed
TLS’ Trusted Firmware Project at
The SHA-256, SHA-3 and Keccak implementations are based on those by the
‘Mbed TLS’ Trusted Firmware Project at
<https://www.trustedfirmware.org/projects/mbed-tls>. The SipHash
implementation is based on that of Daniele Nicolodi, David Rheinsberg
and Tom Gundersen at <https://github.com/c-util/c-siphash>, which is in
Expand Down
6 changes: 3 additions & 3 deletions src/secret.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ static void hash_object(mbedtls_sha3_context *ctx, const SEXP x) {
break;
case RAWSXP:
if (ATTRIB(x) == R_NilValue) {
mbedtls_sha3_update(ctx, (uint8_t *) STDVEC_DATAPTR(x), (size_t) XLENGTH(x));
mbedtls_sha3_update(ctx, (uint8_t *) DATAPTR_RO(x), (size_t) XLENGTH(x));
return;
}
break;
Expand Down Expand Up @@ -301,7 +301,7 @@ SEXP hash_to_sexp(unsigned char *buf, size_t sz, int conv) {
SEXP out;
if (conv == 0) {
out = Rf_allocVector(RAWSXP, sz);
memcpy(STDVEC_DATAPTR(out), buf, sz);
memcpy(DATAPTR(out), buf, sz);
} else if (conv == 1) {
char cbuf[sz + sz + 1];
char *cptr = cbuf;
Expand All @@ -312,7 +312,7 @@ SEXP hash_to_sexp(unsigned char *buf, size_t sz, int conv) {
UNPROTECT(1);
} else {
out = Rf_allocVector(INTSXP, sz / sizeof(int));
memcpy(STDVEC_DATAPTR(out), buf, sz);
memcpy(DATAPTR(out), buf, sz);
}

return out;
Expand Down
4 changes: 2 additions & 2 deletions src/secret2.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ static void hash_object(mbedtls_sha256_context *ctx, const SEXP x) {
break;
case RAWSXP:
if (ATTRIB(x) == R_NilValue) {
mbedtls_sha256_update(ctx, (uint8_t *) STDVEC_DATAPTR(x), (size_t) XLENGTH(x));
mbedtls_sha256_update(ctx, (uint8_t *) DATAPTR_RO(x), (size_t) XLENGTH(x));
return;
}
break;
Expand Down Expand Up @@ -476,7 +476,7 @@ static SEXP secretbase_sha256_impl(const SEXP x, SEXP key, const SEXP convert,
klen = strlen((char *) data);
break;
case RAWSXP:
data = (unsigned char *) STDVEC_DATAPTR(key);
data = (unsigned char *) DATAPTR_RO(key);
klen = XLENGTH(key);
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions src/secret3.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static void hash_object(CSipHash *ctx, const SEXP x) {
break;
case RAWSXP:
if (ATTRIB(x) == R_NilValue) {
c_siphash_append(ctx, (uint8_t *) STDVEC_DATAPTR(x), (size_t) XLENGTH(x));
c_siphash_append(ctx, (uint8_t *) DATAPTR_RO(x), (size_t) XLENGTH(x));
return;
}
break;
Expand Down Expand Up @@ -270,7 +270,7 @@ static SEXP secretbase_siphash_impl(const SEXP x, const SEXP key, const SEXP con
klen = strlen((char *) data);
break;
case RAWSXP:
data = (unsigned char *) STDVEC_DATAPTR(key);
data = (unsigned char *) DATAPTR_RO(key);
klen = XLENGTH(key);
break;
default:
Expand Down

0 comments on commit 6a631c8

Please sign in to comment.