Add support for CHAP with SHA-256

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
This commit is contained in:
Ronnie Sahlberg
2025-01-04 09:09:02 +10:00
parent 95a0d98cfd
commit 34e83f7dbd
6 changed files with 648 additions and 4 deletions

View File

@@ -808,6 +808,29 @@ static void compute_chap_r_sha1(struct iscsi_context *iscsi, int chap_i,
SHA1Result(&ctx, digest);
}
static void compute_chap_r_sha256(struct iscsi_context *iscsi, int chap_i,
unsigned char *passwd,
unsigned char *chap_c,
unsigned char *digest)
{
unsigned char *strp;
unsigned char c;
SHA256Context ctx;
SHA256Reset(&ctx);
c = chap_i;
SHA256Input(&ctx, &c, 1);
SHA256Input(&ctx, passwd, strlen((char *)passwd));
strp = chap_c;
while (*strp != 0) {
c = (h2i(strp[0]) << 4) | h2i(strp[1]);
strp += 2;
SHA256Input(&ctx, &c, 1);
}
SHA256Result(&ctx, digest);
}
static void compute_chap_r(struct iscsi_context *iscsi, int chap_i,
unsigned char *passwd,
unsigned char *chap_c,
@@ -818,6 +841,8 @@ static void compute_chap_r(struct iscsi_context *iscsi, int chap_i,
return compute_chap_r_md5(iscsi, chap_i, passwd, chap_c, digest);
case ISCSI_CHAP_SHA_1:
return compute_chap_r_sha1(iscsi, chap_i, passwd, chap_c, digest);
case ISCSI_CHAP_SHA_256:
return compute_chap_r_sha256(iscsi, chap_i, passwd, chap_c, digest);
}
}
@@ -847,6 +872,9 @@ iscsi_login_add_chap_response(struct iscsi_context *iscsi, struct iscsi_pdu *pdu
case ISCSI_CHAP_SHA_1:
chap_r_size = 20;
break;
case ISCSI_CHAP_SHA_256:
chap_r_size = 32;
break;
}
compute_chap_r(iscsi, iscsi->chap_i,
@@ -1395,6 +1423,9 @@ iscsi_process_login_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu,
case ISCSI_CHAP_SHA_1:
chap_r_size = 20;
break;
case ISCSI_CHAP_SHA_256:
chap_r_size = 32;
break;
}
if (len != 9 + 2 * chap_r_size) {