|
root / base / usr / src / boot / libsa / crypto
crypto Plain Text 141 lines 3.0 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright 2021 Toomas Soome <tsoome@me.com>
#

COMDIR = $(SRC)/common/crypto

SRCS +=		$(CRYPTOSRC)/digest.c
SRCS +=		$(COMDIR)/sha1/sha1.c
SRCS +=		$(COMDIR)/edonr/edonr.c
SRCS +=		$(COMDIR)/skein/skein.c
SRCS +=		$(COMDIR)/skein/skein_iv.c
SRCS +=		$(COMDIR)/skein/skein_block.c
OBJECTS +=	digest.o
OBJECTS +=	sha1.o
OBJECTS +=	edonr.o
OBJECTS +=	skein.o
OBJECTS +=	skein_iv.o
OBJECTS +=	skein_block.o

objs/digest.o: CPPFLAGS +=	-I../../common

pics/digest.o: CPPFLAGS +=	-I../../common

# Do not unroll skein loops, reduce code size
objs/skein_block.o: CPPFLAGS +=	-DSKEIN_LOOP=111

pics/skein_block.o: CPPFLAGS +=	-DSKEIN_LOOP=111

objs/%.o: $(COMDIR)/edonr/%.c
	$(COMPILE.c) -o $@ $<

pics/%.o: $(COMDIR)/edonr/%.c
	$(COMPILE.c) -o $@ $<

objs/%.o: $(COMDIR)/skein/%.c
	$(COMPILE.c) -o $@ $<

pics/%.o: $(COMDIR)/skein/%.c
	$(COMPILE.c) -o $@ $<

objs/%.o: $(CRYPTOSRC)/%.c
	$(COMPILE.c) -o $@ $<

pics/%.o: $(CRYPTOSRC)/%.c
	$(COMPILE.c) -o $@ $<

objs/%.o: $(COMDIR)/sha1/%.c
	$(COMPILE.c) -o $@ $<

pics/%.o: $(COMDIR)/sha1/%.c
	$(COMPILE.c) -o $@ $<

sha1-x86_64.S: $(COMDIR)/sha1/amd64/sha1-x86_64.pl
	$(PERL) $? $@

pics/sha1-x86_64.o: sha1-x86_64.S
	$(COMPILE.s) -o $@ ${@F:.o=.S}

#include <sys/cdefs.h>
#include <stand.h>
#include <sys/sha1.h>

#include <bootstrap.h>

void
sha1(void *data, size_t size, uint8_t *result)
{
	SHA1_CTX sha1_ctx;

	SHA1Init(&sha1_ctx);
	SHA1Update(&sha1_ctx, data, size);
	SHA1Final(result, &sha1_ctx);
}

static int
command_sha1(int argc, char **argv)
{
	void *ptr;
	size_t size, i;
	uint8_t resultbuf[SHA1_DIGEST_LENGTH];

	/*
	 * usage: address size
	 */
	if (argc != 3) {
		command_errmsg = "usage: address size";
		return (CMD_ERROR);
	}

	ptr = (void *)(uintptr_t)strtol(argv[1], NULL, 0);
	size = strtol(argv[2], NULL, 0);
	sha1(ptr, size, resultbuf);

	for (i = 0; i < SHA1_DIGEST_LENGTH; i++)
		printf("%02x", resultbuf[i]);
	printf("\n");
	return (CMD_OK);
}

COMMAND_SET(sha1, "sha1", "print the sha1 checksum", command_sha1);
/*
 * This file and its contents are supplied under the terms of the
 * Common Development and Distribution License ("CDDL"), version 1.0.
 * You may only use this file in accordance with the terms of version
 * 1.0 of the CDDL.
 *
 * A full copy of the text of the CDDL should have accompanied this
 * source.  A copy of the CDDL is also available via the Internet at
 * http://www.illumos.org/license/CDDL.
 */

/*
 * Copyright 2019 Toomas Soome <tsoome@me.com>
 */

#ifndef _LIBCRYPTO_H
#define	_LIBCRYPTO_H

#ifdef __cplusplus
extern "C" {
#endif

extern void sha1(void *, size_t, uint8_t *);

#ifdef __cplusplus
}
#endif

#endif /* _LIBCRYPTO_H */