diff options
author | tb <> | 2023-12-20 11:33:52 +0000 |
---|---|---|
committer | tb <> | 2023-12-20 11:33:52 +0000 |
commit | c51b1ef48597ca2e1456b504f3be9077a5e42ba2 (patch) | |
tree | b3b5837a8f7d395da5bbff1f6819de7e9cef3887 | |
parent | dc004816546e0754b33ec435858014bde0ae7547 (diff) | |
download | openbsd-c51b1ef48597ca2e1456b504f3be9077a5e42ba2.tar.gz openbsd-c51b1ef48597ca2e1456b504f3be9077a5e42ba2.tar.bz2 openbsd-c51b1ef48597ca2e1456b504f3be9077a5e42ba2.zip |
Improve local variable names
Rename the slightly awkward buf_offset into partial_len and rename
buf_avail into partial_needed to match.
suggested by jsing
-rw-r--r-- | src/lib/libcrypto/evp/evp_enc.c | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c index ee1c12b70c..0c18a8833b 100644 --- a/src/lib/libcrypto/evp/evp_enc.c +++ b/src/lib/libcrypto/evp/evp_enc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evp_enc.c,v 1.67 2023/12/20 11:31:17 tb Exp $ */ | 1 | /* $OpenBSD: evp_enc.c,v 1.68 2023/12/20 11:33:52 tb 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 | * |
@@ -298,7 +298,7 @@ EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | |||
298 | { | 298 | { |
299 | const int block_size = ctx->cipher->block_size; | 299 | const int block_size = ctx->cipher->block_size; |
300 | const int block_mask = ctx->block_mask; | 300 | const int block_mask = ctx->block_mask; |
301 | int buf_offset = ctx->partial_len; | 301 | int partial_len = ctx->partial_len; |
302 | int len = 0, total_len = 0; | 302 | int len = 0, total_len = 0; |
303 | 303 | ||
304 | *outl = 0; | 304 | *outl = 0; |
@@ -312,48 +312,48 @@ EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | |||
312 | if ((ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) != 0) | 312 | if ((ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) != 0) |
313 | return evp_cipher(ctx, out, outl, in, inl); | 313 | return evp_cipher(ctx, out, outl, in, inl); |
314 | 314 | ||
315 | if (buf_offset == 0 && (inl & block_mask) == 0) | 315 | if (partial_len == 0 && (inl & block_mask) == 0) |
316 | return evp_cipher(ctx, out, outl, in, inl); | 316 | return evp_cipher(ctx, out, outl, in, inl); |
317 | 317 | ||
318 | /* XXX - check that block_size > buf_offset. */ | 318 | /* XXX - check that block_size > partial_len. */ |
319 | if (block_size > sizeof(ctx->buf)) { | 319 | if (block_size > sizeof(ctx->buf)) { |
320 | EVPerror(EVP_R_BAD_BLOCK_LENGTH); | 320 | EVPerror(EVP_R_BAD_BLOCK_LENGTH); |
321 | return 0; | 321 | return 0; |
322 | } | 322 | } |
323 | 323 | ||
324 | if (buf_offset != 0) { | 324 | if (partial_len != 0) { |
325 | int buf_avail; | 325 | int partial_needed; |
326 | 326 | ||
327 | if ((buf_avail = block_size - buf_offset) > inl) { | 327 | if ((partial_needed = block_size - partial_len) > inl) { |
328 | memcpy(&ctx->buf[buf_offset], in, inl); | 328 | memcpy(&ctx->buf[partial_len], in, inl); |
329 | ctx->partial_len += inl; | 329 | ctx->partial_len += inl; |
330 | return 1; | 330 | return 1; |
331 | } | 331 | } |
332 | 332 | ||
333 | /* | 333 | /* |
334 | * Once the first buf_avail bytes from in are processed, the | 334 | * Once the first partial_needed bytes from in are processed, |
335 | * amount of data left that is a multiple of the block length is | 335 | * the number of multiples of block_size of data remaining is |
336 | * (inl - buf_avail) & ~block_mask. Ensure that this plus the | 336 | * (inl - partial_needed) & ~block_mask. Ensure that this |
337 | * block processed from ctx->buf doesn't overflow. | 337 | * plus the block processed from ctx->buf doesn't overflow. |
338 | */ | 338 | */ |
339 | if (((inl - buf_avail) & ~block_mask) > INT_MAX - block_size) { | 339 | if (((inl - partial_needed) & ~block_mask) > INT_MAX - block_size) { |
340 | EVPerror(EVP_R_TOO_LARGE); | 340 | EVPerror(EVP_R_TOO_LARGE); |
341 | return 0; | 341 | return 0; |
342 | } | 342 | } |
343 | memcpy(&ctx->buf[buf_offset], in, buf_avail); | 343 | memcpy(&ctx->buf[partial_len], in, partial_needed); |
344 | 344 | ||
345 | len = 0; | 345 | len = 0; |
346 | if (!evp_cipher(ctx, out, &len, ctx->buf, block_size)) | 346 | if (!evp_cipher(ctx, out, &len, ctx->buf, block_size)) |
347 | return 0; | 347 | return 0; |
348 | total_len = len; | 348 | total_len = len; |
349 | 349 | ||
350 | inl -= buf_avail; | 350 | inl -= partial_needed; |
351 | in += buf_avail; | 351 | in += partial_needed; |
352 | out += len; | 352 | out += len; |
353 | } | 353 | } |
354 | 354 | ||
355 | buf_offset = inl & block_mask; | 355 | partial_len = inl & block_mask; |
356 | if ((inl -= buf_offset) > 0) { | 356 | if ((inl -= partial_len) > 0) { |
357 | if (INT_MAX - inl < total_len) | 357 | if (INT_MAX - inl < total_len) |
358 | return 0; | 358 | return 0; |
359 | len = 0; | 359 | len = 0; |
@@ -364,9 +364,9 @@ EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | |||
364 | total_len += len; | 364 | total_len += len; |
365 | } | 365 | } |
366 | 366 | ||
367 | if (buf_offset != 0) | 367 | if (partial_len != 0) |
368 | memcpy(ctx->buf, &in[inl], buf_offset); | 368 | memcpy(ctx->buf, &in[inl], partial_len); |
369 | ctx->partial_len = buf_offset; | 369 | ctx->partial_len = partial_len; |
370 | 370 | ||
371 | *outl = total_len; | 371 | *outl = total_len; |
372 | 372 | ||
@@ -383,7 +383,7 @@ int | |||
383 | EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | 383 | EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) |
384 | { | 384 | { |
385 | const int block_size = ctx->cipher->block_size; | 385 | const int block_size = ctx->cipher->block_size; |
386 | int buf_offset = ctx->partial_len; | 386 | int partial_len = ctx->partial_len; |
387 | int pad; | 387 | int pad; |
388 | 388 | ||
389 | *outl = 0; | 389 | *outl = 0; |
@@ -391,7 +391,7 @@ EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | |||
391 | if ((ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) != 0) | 391 | if ((ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) != 0) |
392 | return evp_cipher(ctx, out, outl, NULL, 0); | 392 | return evp_cipher(ctx, out, outl, NULL, 0); |
393 | 393 | ||
394 | /* XXX - check that block_size > buf_offset. */ | 394 | /* XXX - check that block_size > partial_len. */ |
395 | if (block_size > sizeof(ctx->buf)) { | 395 | if (block_size > sizeof(ctx->buf)) { |
396 | EVPerror(EVP_R_BAD_BLOCK_LENGTH); | 396 | EVPerror(EVP_R_BAD_BLOCK_LENGTH); |
397 | return 0; | 397 | return 0; |
@@ -400,15 +400,15 @@ EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | |||
400 | return 1; | 400 | return 1; |
401 | 401 | ||
402 | if ((ctx->flags & EVP_CIPH_NO_PADDING) != 0) { | 402 | if ((ctx->flags & EVP_CIPH_NO_PADDING) != 0) { |
403 | if (buf_offset != 0) { | 403 | if (partial_len != 0) { |
404 | EVPerror(EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH); | 404 | EVPerror(EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH); |
405 | return 0; | 405 | return 0; |
406 | } | 406 | } |
407 | return 1; | 407 | return 1; |
408 | } | 408 | } |
409 | 409 | ||
410 | pad = block_size - buf_offset; | 410 | pad = block_size - partial_len; |
411 | memset(&ctx->buf[buf_offset], pad, pad); | 411 | memset(&ctx->buf[partial_len], pad, pad); |
412 | 412 | ||
413 | return evp_cipher(ctx, out, outl, ctx->buf, block_size); | 413 | return evp_cipher(ctx, out, outl, ctx->buf, block_size); |
414 | } | 414 | } |
@@ -488,7 +488,7 @@ int | |||
488 | EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | 488 | EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) |
489 | { | 489 | { |
490 | const int block_size = ctx->cipher->block_size; | 490 | const int block_size = ctx->cipher->block_size; |
491 | int buf_offset = ctx->partial_len; | 491 | int partial_len = ctx->partial_len; |
492 | int i, pad, plain_len; | 492 | int i, pad, plain_len; |
493 | 493 | ||
494 | *outl = 0; | 494 | *outl = 0; |
@@ -497,7 +497,7 @@ EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | |||
497 | return evp_cipher(ctx, out, outl, NULL, 0); | 497 | return evp_cipher(ctx, out, outl, NULL, 0); |
498 | 498 | ||
499 | if ((ctx->flags & EVP_CIPH_NO_PADDING) != 0) { | 499 | if ((ctx->flags & EVP_CIPH_NO_PADDING) != 0) { |
500 | if (buf_offset != 0) { | 500 | if (partial_len != 0) { |
501 | EVPerror(EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH); | 501 | EVPerror(EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH); |
502 | return 0; | 502 | return 0; |
503 | } | 503 | } |
@@ -507,7 +507,7 @@ EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | |||
507 | if (block_size == 1) | 507 | if (block_size == 1) |
508 | return 1; | 508 | return 1; |
509 | 509 | ||
510 | if (buf_offset != 0 || !ctx->final_used) { | 510 | if (partial_len != 0 || !ctx->final_used) { |
511 | EVPerror(EVP_R_WRONG_FINAL_BLOCK_LENGTH); | 511 | EVPerror(EVP_R_WRONG_FINAL_BLOCK_LENGTH); |
512 | return 0; | 512 | return 0; |
513 | } | 513 | } |