1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2013 Saso Kiselkov. All rights reserved.
23 * Use is subject to license terms.
24 */
25 #include <sys/zfs_context.h>
26 #include <sys/zio.h>
27 #include <sys/edonr.h>
28
29 /*
30 * zio_checksum interface for the Edon-R hash function
31 */
32 void
33 zio_checksum_EdonR512_256(const void *buf, uint64_t size, zio_cksum_t *zcp)
34 {
35 uint8_t hash[EdonR512_DIGEST_SIZE];
36
37 EdonRHash(512, buf, size * 8, hash);
38 bcopy(&hash[000], &zcp->zc_word[0], sizeof (zcp->zc_word[0]));
39 bcopy(&hash[010], &zcp->zc_word[1], sizeof (zcp->zc_word[0]));
40 bcopy(&hash[020], &zcp->zc_word[2], sizeof (zcp->zc_word[0]));
41 bcopy(&hash[030], &zcp->zc_word[3], sizeof (zcp->zc_word[0]));
42 }
43
44 void
45 zio_checksum_EdonR512_256_byteswap(const void *buf, uint64_t size,
46 zio_cksum_t *zcp)
47 {
48 zio_checksum_EdonR512_256(buf, size, zcp);
49 zcp->zc_word[0] = BSWAP_64(zcp->zc_word[0]);
50 zcp->zc_word[1] = BSWAP_64(zcp->zc_word[1]);
51 zcp->zc_word[2] = BSWAP_64(zcp->zc_word[2]);
52 zcp->zc_word[3] = BSWAP_64(zcp->zc_word[3]);
53 }