diff options
| author | jsing <> | 2024-03-28 04:56:47 +0000 |
|---|---|---|
| committer | jsing <> | 2024-03-28 04:56:47 +0000 |
| commit | bcf6321e657f82b7903d753783bd5e50612692b4 (patch) | |
| tree | dcc9e882eb6b54fbe808180cfb2f36a8037b4a2e /src | |
| parent | 315693de05b08c3f051a52e78d7a801d8025ee4e (diff) | |
| download | openbsd-bcf6321e657f82b7903d753783bd5e50612692b4.tar.gz openbsd-bcf6321e657f82b7903d753783bd5e50612692b4.tar.bz2 openbsd-bcf6321e657f82b7903d753783bd5e50612692b4.zip | |
Inline functions from md32_common.h for ripemd.
No change to generated assembly.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/ripemd/ripemd.c | 102 |
1 files changed, 101 insertions, 1 deletions
diff --git a/src/lib/libcrypto/ripemd/ripemd.c b/src/lib/libcrypto/ripemd/ripemd.c index 344d9f6689..229b712e6b 100644 --- a/src/lib/libcrypto/ripemd/ripemd.c +++ b/src/lib/libcrypto/ripemd/ripemd.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ripemd.c,v 1.7 2023/08/10 12:27:35 jsing Exp $ */ | 1 | /* $OpenBSD: ripemd.c,v 1.8 2024/03/28 04:56:47 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -100,8 +100,108 @@ __END_HIDDEN_DECLS | |||
| 100 | } while (0) | 100 | } while (0) |
| 101 | #define HASH_BLOCK_DATA_ORDER ripemd160_block_data_order | 101 | #define HASH_BLOCK_DATA_ORDER ripemd160_block_data_order |
| 102 | 102 | ||
| 103 | #define HASH_NO_UPDATE | ||
| 104 | #define HASH_NO_TRANSFORM | ||
| 105 | #define HASH_NO_FINAL | ||
| 106 | |||
| 103 | #include "md32_common.h" | 107 | #include "md32_common.h" |
| 104 | 108 | ||
| 109 | int | ||
| 110 | HASH_UPDATE(HASH_CTX *c, const void *data_, size_t len) | ||
| 111 | { | ||
| 112 | const unsigned char *data = data_; | ||
| 113 | unsigned char *p; | ||
| 114 | HASH_LONG l; | ||
| 115 | size_t n; | ||
| 116 | |||
| 117 | if (len == 0) | ||
| 118 | return 1; | ||
| 119 | |||
| 120 | l = (c->Nl + (((HASH_LONG)len) << 3))&0xffffffffUL; | ||
| 121 | /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to | ||
| 122 | * Wei Dai <weidai@eskimo.com> for pointing it out. */ | ||
| 123 | if (l < c->Nl) /* overflow */ | ||
| 124 | c->Nh++; | ||
| 125 | c->Nh+=(HASH_LONG)(len>>29); /* might cause compiler warning on 16-bit */ | ||
| 126 | c->Nl = l; | ||
| 127 | |||
| 128 | n = c->num; | ||
| 129 | if (n != 0) { | ||
| 130 | p = (unsigned char *)c->data; | ||
| 131 | |||
| 132 | if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK) { | ||
| 133 | memcpy (p + n, data, HASH_CBLOCK - n); | ||
| 134 | HASH_BLOCK_DATA_ORDER (c, p, 1); | ||
| 135 | n = HASH_CBLOCK - n; | ||
| 136 | data += n; | ||
| 137 | len -= n; | ||
| 138 | c->num = 0; | ||
| 139 | memset (p,0,HASH_CBLOCK); /* keep it zeroed */ | ||
| 140 | } else { | ||
| 141 | memcpy (p + n, data, len); | ||
| 142 | c->num += (unsigned int)len; | ||
| 143 | return 1; | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | n = len/HASH_CBLOCK; | ||
| 148 | if (n > 0) { | ||
| 149 | HASH_BLOCK_DATA_ORDER (c, data, n); | ||
| 150 | n *= HASH_CBLOCK; | ||
| 151 | data += n; | ||
| 152 | len -= n; | ||
| 153 | } | ||
| 154 | |||
| 155 | if (len != 0) { | ||
| 156 | p = (unsigned char *)c->data; | ||
| 157 | c->num = (unsigned int)len; | ||
| 158 | memcpy (p, data, len); | ||
| 159 | } | ||
| 160 | return 1; | ||
| 161 | } | ||
| 162 | |||
| 163 | void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data) | ||
| 164 | { | ||
| 165 | HASH_BLOCK_DATA_ORDER (c, data, 1); | ||
| 166 | } | ||
| 167 | |||
| 168 | int HASH_FINAL (unsigned char *md, HASH_CTX *c) | ||
| 169 | { | ||
| 170 | unsigned char *p = (unsigned char *)c->data; | ||
| 171 | size_t n = c->num; | ||
| 172 | |||
| 173 | p[n] = 0x80; /* there is always room for one */ | ||
| 174 | n++; | ||
| 175 | |||
| 176 | if (n > (HASH_CBLOCK - 8)) { | ||
| 177 | memset (p + n, 0, HASH_CBLOCK - n); | ||
| 178 | n = 0; | ||
| 179 | HASH_BLOCK_DATA_ORDER (c, p, 1); | ||
| 180 | } | ||
| 181 | memset (p + n, 0, HASH_CBLOCK - 8 - n); | ||
| 182 | |||
| 183 | p += HASH_CBLOCK - 8; | ||
| 184 | #if defined(DATA_ORDER_IS_BIG_ENDIAN) | ||
| 185 | HOST_l2c(c->Nh, p); | ||
| 186 | HOST_l2c(c->Nl, p); | ||
| 187 | #elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) | ||
| 188 | HOST_l2c(c->Nl, p); | ||
| 189 | HOST_l2c(c->Nh, p); | ||
| 190 | #endif | ||
| 191 | p -= HASH_CBLOCK; | ||
| 192 | HASH_BLOCK_DATA_ORDER (c, p, 1); | ||
| 193 | c->num = 0; | ||
| 194 | memset (p, 0, HASH_CBLOCK); | ||
| 195 | |||
| 196 | #ifndef HASH_MAKE_STRING | ||
| 197 | #error "HASH_MAKE_STRING must be defined!" | ||
| 198 | #else | ||
| 199 | HASH_MAKE_STRING(c, md); | ||
| 200 | #endif | ||
| 201 | |||
| 202 | return 1; | ||
| 203 | } | ||
| 204 | |||
| 105 | #if 0 | 205 | #if 0 |
| 106 | #define F1(x,y,z) ((x)^(y)^(z)) | 206 | #define F1(x,y,z) ((x)^(y)^(z)) |
| 107 | #define F2(x,y,z) (((x)&(y))|((~x)&z)) | 207 | #define F2(x,y,z) (((x)&(y))|((~x)&z)) |
