-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iscsi-scst: Add SHA256 and SHA3-256 support to CHAP
Use the kernel userspace AL_ALG API to access additional hash functions "sha256" and "sha3-256". If configured for CHAP, on iSCSI login the client will present an ordered list of desired algorithms. During this negotiation, if the client requests SHA256 or SHA3-256 we verify that the kernel supports the algorithm before agreeing to use it.
- Loading branch information
1 parent
6c5e8ad
commit 146d79e
Showing
4 changed files
with
207 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* | ||
* af_alg - wrapper functions to call AF_ALG hash algorithms. | ||
* | ||
* Copyright (C) 2025 Brian Meagher <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation, version 2 | ||
* of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
#include "af_alg.h" | ||
|
||
#include <sys/socket.h> | ||
#include <linux/if_alg.h> | ||
#include <string.h> | ||
#include <sys/param.h> | ||
#include <stdbool.h> | ||
|
||
int af_alg_init(const char *algorithm) | ||
{ | ||
int sockfd, datafd, algo_len; | ||
struct sockaddr_alg sa = { | ||
.salg_family = AF_ALG, | ||
.salg_type = "hash", | ||
}; | ||
|
||
algo_len = strlen(algorithm); | ||
if (algo_len >= sizeof(sa.salg_name)) | ||
return -1; | ||
|
||
sockfd = socket(AF_ALG, SOCK_SEQPACKET, 0); | ||
if (sockfd == -1) | ||
return -1; | ||
|
||
/* +1 for null-terminator */ | ||
memcpy(sa.salg_name, algorithm, algo_len + 1); | ||
|
||
if (bind(sockfd, (struct sockaddr *)&sa, sizeof(sa)) == -1) { | ||
close(sockfd); | ||
return -1; | ||
} | ||
|
||
datafd = accept(sockfd, NULL, 0); | ||
if (datafd < 0) { | ||
close(sockfd); | ||
return -1; | ||
} | ||
close(sockfd); | ||
return datafd; | ||
} | ||
|
||
void af_alg_update(int datafd, const void *data_in, size_t len) | ||
{ | ||
send(datafd, data_in, len, MSG_MORE); | ||
} | ||
|
||
ssize_t af_alg_final(int datafd, void *out, size_t len) | ||
{ | ||
char buffer[1024]; | ||
ssize_t bytes; | ||
|
||
send(datafd, NULL, 0, 0); | ||
|
||
bytes = recv(datafd, buffer, sizeof(buffer), 0); | ||
memcpy(out, buffer, MIN(len, bytes)); | ||
return bytes; | ||
} | ||
|
||
bool af_alg_supported(char *alg) | ||
{ | ||
int sock = af_alg_init(alg); | ||
|
||
if (sock < 0) | ||
return false; | ||
close(sock); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
/* | ||
* Copyright (C) 2025 Brian Meagher <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation, version 2 | ||
* of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
#ifndef SCST_AF_ALG_H | ||
#define SCST_AF_ALG_H | ||
|
||
#include <unistd.h> | ||
#include <stdbool.h> | ||
|
||
#define SCST_AF_ALG_SHA256_NAME "sha256" | ||
#define SCST_AF_ALG_SHA3_256_NAME "sha3-256" | ||
|
||
int af_alg_init(const char *algorithm); | ||
void af_alg_update(int datafd, const void *data_in, size_t len); | ||
ssize_t af_alg_final(int datafd, void *out, size_t len); | ||
bool af_alg_supported(char *alg); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters