|
| 1 | +/*- |
| 2 | + * Copyright 2009 Colin Percival, 2011 ArtForz, 2013 Neisklar, 2014 James Lovejoy |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions |
| 7 | + * are met: |
| 8 | + * 1. Redistributions of source code must retain the above copyright |
| 9 | + * notice, this list of conditions and the following disclaimer. |
| 10 | + * 2. 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 | + * |
| 14 | + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 15 | + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 18 | + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 19 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 20 | + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 21 | + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 22 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 23 | + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 24 | + * SUCH DAMAGE. |
| 25 | + * |
| 26 | + * This file was originally written by Colin Percival as part of the Tarsnap |
| 27 | + * online backup system. |
| 28 | + */ |
| 29 | + |
| 30 | +#include "Lyra2RE.h" |
| 31 | +#include <stdlib.h> |
| 32 | +#include <stdint.h> |
| 33 | +#include <string.h> |
| 34 | +#include <stdio.h> |
| 35 | +#include "sph_blake.h" |
| 36 | +#include "sph_groestl.h" |
| 37 | +#include "sph_cubehash.h" |
| 38 | +#include "sph_bmw.h" |
| 39 | +#include "sph_keccak.h" |
| 40 | +#include "sph_skein.h" |
| 41 | +#include "Lyra2.h" |
| 42 | + |
| 43 | +void lyra2re_hash(const char* input, char* output) |
| 44 | +{ |
| 45 | + sph_blake256_context ctx_blake; |
| 46 | + sph_groestl256_context ctx_groestl; |
| 47 | + sph_keccak256_context ctx_keccak; |
| 48 | + sph_skein256_context ctx_skein; |
| 49 | + |
| 50 | + uint32_t hashA[8], hashB[8]; |
| 51 | + |
| 52 | + sph_blake256_init(&ctx_blake); |
| 53 | + sph_blake256 (&ctx_blake, input, 80); |
| 54 | + sph_blake256_close (&ctx_blake, hashA); |
| 55 | + |
| 56 | + sph_keccak256_init(&ctx_keccak); |
| 57 | + sph_keccak256 (&ctx_keccak,hashA, 32); |
| 58 | + sph_keccak256_close(&ctx_keccak, hashB); |
| 59 | + |
| 60 | + LYRA2_old(hashA, 32, hashB, 32, hashB, 32, 1, 8, 8); |
| 61 | + |
| 62 | + sph_skein256_init(&ctx_skein); |
| 63 | + sph_skein256 (&ctx_skein, hashA, 32); |
| 64 | + sph_skein256_close(&ctx_skein, hashB); |
| 65 | + |
| 66 | + sph_groestl256_init(&ctx_groestl); |
| 67 | + sph_groestl256 (&ctx_groestl, hashB, 32); |
| 68 | + sph_groestl256_close(&ctx_groestl, hashA); |
| 69 | + |
| 70 | + memcpy(output, hashA, 32); |
| 71 | +} |
| 72 | + |
| 73 | +void lyra2re2_hash(const char* input, char* output) |
| 74 | +{ |
| 75 | + sph_blake256_context ctx_blake; |
| 76 | + sph_cubehash256_context ctx_cubehash; |
| 77 | + sph_keccak256_context ctx_keccak; |
| 78 | + sph_skein256_context ctx_skein; |
| 79 | + sph_bmw256_context ctx_bmw; |
| 80 | + |
| 81 | + uint32_t hashA[8], hashB[8]; |
| 82 | + |
| 83 | + sph_blake256_init(&ctx_blake); |
| 84 | + sph_blake256(&ctx_blake, input, 80); |
| 85 | + sph_blake256_close (&ctx_blake, hashA); |
| 86 | + |
| 87 | + sph_keccak256_init(&ctx_keccak); |
| 88 | + sph_keccak256(&ctx_keccak, hashA, 32); |
| 89 | + sph_keccak256_close(&ctx_keccak, hashB); |
| 90 | + |
| 91 | + sph_cubehash256_init(&ctx_cubehash); |
| 92 | + sph_cubehash256(&ctx_cubehash, hashB, 32); |
| 93 | + sph_cubehash256_close(&ctx_cubehash, hashA); |
| 94 | + |
| 95 | + LYRA2(hashB, 32, hashA, 32, hashA, 32, 1, 4, 4); |
| 96 | + |
| 97 | + sph_skein256_init(&ctx_skein); |
| 98 | + sph_skein256(&ctx_skein, hashB, 32); |
| 99 | + sph_skein256_close(&ctx_skein, hashA); |
| 100 | + |
| 101 | + sph_cubehash256_init(&ctx_cubehash); |
| 102 | + sph_cubehash256(&ctx_cubehash, hashA, 32); |
| 103 | + sph_cubehash256_close(&ctx_cubehash, hashB); |
| 104 | + |
| 105 | + sph_bmw256_init(&ctx_bmw); |
| 106 | + sph_bmw256(&ctx_bmw, hashB, 32); |
| 107 | + sph_bmw256_close(&ctx_bmw, hashA); |
| 108 | + |
| 109 | + memcpy(output, hashA, 32); |
| 110 | +} |
0 commit comments