| 190 | // |
| 191 | |
| 192 | static ssize_t // O - Size of hash or `-1` on error |
| 193 | hash_data(const char *algorithm, // I - Algorithm |
| 194 | unsigned char *hash, // I - Hash buffer |
| 195 | size_t hashsize, // I - Size of hash buffer |
| 196 | const void *a, // I - First block |
| 197 | size_t alen, // I - Length of first block |
| 198 | const void *b, // I - Second block or `NULL` for none |
| 199 | size_t blen) // I - Length of second block or `0` for none |
| 200 | { |
| 201 | #if defined(HAVE_OPENSSL) || defined(HAVE_GNUTLS) |
| 202 | unsigned hashlen; // Length of hash |
| 203 | unsigned char hashtemp[64]; // Temporary hash buffer |
| 204 | #else |
| 205 | if (strcmp(algorithm, "md5") && (b || blen != 0)) |
| 206 | { |
| 207 | // Second block hashing is not supported without OpenSSL or GnuTLS |
| 208 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Unsupported without GnuTLS or OpenSSL/LibreSSL."), 1); |
| 209 | |
| 210 | return (-1); |
| 211 | } |
| 212 | #endif |
| 213 | |
| 214 | if (!strcmp(algorithm, "md5")) |
| 215 | { |
| 216 | // Some versions of GNU TLS and OpenSSL disable MD5 without warning... |
| 217 | _cups_md5_state_t state; // MD5 state info |
| 218 | |
| 219 | if (hashsize < 16) |
| 220 | goto too_small; |
| 221 | |
| 222 | _cupsMD5Init(&state); |
| 223 | _cupsMD5Append(&state, a, (int)alen); |
| 224 | if (b && blen) |
| 225 | _cupsMD5Append(&state, b, (int)blen); |
| 226 | _cupsMD5Finish(&state, hash); |
| 227 | |
| 228 | return (16); |
| 229 | } |
| 230 | |
| 231 | #ifdef HAVE_OPENSSL |
| 232 | const EVP_MD *md = NULL; // Message digest implementation |
| 233 | EVP_MD_CTX *ctx; // Context |
| 234 | |
| 235 | |
| 236 | if (!strcmp(algorithm, "sha")) |
| 237 | { |
| 238 | // SHA-1 |
| 239 | md = EVP_sha1(); |
| 240 | } |
| 241 | else if (!strcmp(algorithm, "sha2-224")) |
| 242 | { |
| 243 | md = EVP_sha224(); |
| 244 | } |
| 245 | else if (!strcmp(algorithm, "sha2-256")) |
| 246 | { |
| 247 | md = EVP_sha256(); |
| 248 | } |
| 249 | else if (!strcmp(algorithm, "sha2-384")) |
no test coverage detected