* Detect wrap-around, which means it is time to renegotiate
* the session to get a new key and/or fixed field.
*/
- return (c == 0) ? -1 : 0;
+ return (c == 0) ? 0 : 1;
}
static
printf("\n");
#endif
- _gcm_iv_increment(ioq->iv);
+ ok = _gcm_iv_increment(ioq->iv);
+ if (!ok) {
+ ioq->error = HAMMER2_IOQ_ERROR_IVWRAP;
+ goto fail_out;
+ }
*out_size = u_len + f_len + HAMMER2_CRYPTO_TAG_SIZE;
return 0;
fail:
+ ioq->error = HAMMER2_IOQ_ERROR_ALGO;
+fail_out:
if (DebugOpt)
fprintf(stderr, "error during encrypt_chunk\n");
return -1;
/* Re-initialize with new IV (but without redoing the key schedule) */
ok = EVP_DecryptInit_ex(&ioq->ctx, NULL, NULL, NULL, ioq->iv);
- if (!ok)
- goto fail;
+ if (!ok) {
+ ioq->error = HAMMER2_IOQ_ERROR_ALGO;
+ goto fail_out;
+ }
#ifdef CRYPTO_DEBUG
printf("dec_chunk iv: ");
ok = EVP_CIPHER_CTX_ctrl(&ioq->ctx, EVP_CTRL_GCM_SET_TAG,
HAMMER2_CRYPTO_TAG_SIZE,
ct + out_size);
- if (!ok)
- goto fail;
+ if (!ok) {
+ ioq->error = HAMMER2_IOQ_ERROR_ALGO;
+ goto fail_out;
+ }
ok = EVP_DecryptUpdate(&ioq->ctx, pt, &u_len, ct, out_size);
if (!ok)
if (!ok)
goto fail;
- _gcm_iv_increment(ioq->iv);
+ ok = _gcm_iv_increment(ioq->iv);
+ if (!ok) {
+ ioq->error = HAMMER2_IOQ_ERROR_IVWRAP;
+ goto fail_out;
+ }
*consume_size = u_len + f_len + HAMMER2_CRYPTO_TAG_SIZE;
return 0;
fail:
+ ioq->error = HAMMER2_IOQ_ERROR_MACFAIL;
+fail_out:
if (DebugOpt)
fprintf(stderr, "error during decrypt_chunk (likely authentication error)\n");
return -1;
case HAMMER2_IOQ_ERROR_TRANS:
errstr = "err=IOQ:BADTRANS";
break;
+ case HAMMER2_IOQ_ERROR_IVWRAP:
+ errstr = "err=IOQ:IVWRAP";
+ break;
+ case HAMMER2_IOQ_ERROR_MACFAIL:
+ errstr = "err=IOQ:MACFAIL";
+ break;
+ case HAMMER2_IOQ_ERROR_ALGO:
+ errstr = "err=IOQ:ALGOFAIL";
+ break;
case HAMMER2_MSG_ERR_NOSUPP:
errstr = "err=NOSUPPORT";
break;
#define HAMMER2_IOQ_ERROR_MSGSEQ 15 /* message sequence error */
#define HAMMER2_IOQ_ERROR_EALREADY 16 /* ignore this message */
#define HAMMER2_IOQ_ERROR_TRANS 17 /* state transaction issue */
+#define HAMMER2_IOQ_ERROR_IVWRAP 18 /* IVs exhaused */
+#define HAMMER2_IOQ_ERROR_MACFAIL 19 /* MAC of encryption algorithm failed */
+#define HAMMER2_IOQ_ERROR_ALGO 20 /* Misc. encryption algorithm error */
#define HAMMER2_IOQ_MAXIOVEC 16