Monero
Loading...
Searching...
No Matches
blake2-impl.h
Go to the documentation of this file.
1/*
2Copyright (c) 2018-2019, tevador <tevador@gmail.com>
3
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of the copyright holder nor the
14 names of its contributors may be used to endorse or promote products
15 derived from this software without specific prior written permission.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29/* Original code from Argon2 reference source code package used under CC0 Licence
30 * https://github.com/P-H-C/phc-winner-argon2
31 * Copyright 2015
32 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
33*/
34
35#ifndef PORTABLE_BLAKE2_IMPL_H
36#define PORTABLE_BLAKE2_IMPL_H
37
38#include <stdint.h>
39
40#include "endian.h"
41
42static FORCE_INLINE uint64_t load48(const void *src) {
43 const uint8_t *p = (const uint8_t *)src;
44 uint64_t w = *p++;
45 w |= (uint64_t)(*p++) << 8;
46 w |= (uint64_t)(*p++) << 16;
47 w |= (uint64_t)(*p++) << 24;
48 w |= (uint64_t)(*p++) << 32;
49 w |= (uint64_t)(*p++) << 40;
50 return w;
51}
52
53static FORCE_INLINE void store48(void *dst, uint64_t w) {
54 uint8_t *p = (uint8_t *)dst;
55 *p++ = (uint8_t)w;
56 w >>= 8;
57 *p++ = (uint8_t)w;
58 w >>= 8;
59 *p++ = (uint8_t)w;
60 w >>= 8;
61 *p++ = (uint8_t)w;
62 w >>= 8;
63 *p++ = (uint8_t)w;
64 w >>= 8;
65 *p++ = (uint8_t)w;
66}
67
68static FORCE_INLINE uint32_t rotr32(const uint32_t w, const unsigned c) {
69 return (w >> c) | (w << (32 - c));
70}
71
72static FORCE_INLINE uint64_t rotr64(const uint64_t w, const unsigned c) {
73 return (w >> c) | (w << (64 - c));
74}
75
76#endif
static FORCE_INLINE uint64_t rotr64(const uint64_t w, const unsigned c)
Definition blake2-impl.h:72
static FORCE_INLINE void store48(void *dst, uint64_t w)
Definition blake2-impl.h:53
static FORCE_INLINE uint64_t load48(const void *src)
Definition blake2-impl.h:42
#define rotr32(x)
Definition blamka-round-avx2.h:46
#define FORCE_INLINE
Definition endian.h:10
unsigned int uint32_t
Definition stdint.h:126
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136