Changeset View
Changeset View
Standalone View
Standalone View
head/sys/geom/eli/g_eli.h
Show First 20 Lines • Show All 411 Lines • ▼ Show 20 Lines | g_eli_str2ealgo(const char *name) | ||||
else if (strcasecmp("null-cbc", name) == 0) | else if (strcasecmp("null-cbc", name) == 0) | ||||
return (CRYPTO_NULL_CBC); | return (CRYPTO_NULL_CBC); | ||||
else if (strcasecmp("aes", name) == 0) | else if (strcasecmp("aes", name) == 0) | ||||
return (CRYPTO_AES_XTS); | return (CRYPTO_AES_XTS); | ||||
else if (strcasecmp("aes-cbc", name) == 0) | else if (strcasecmp("aes-cbc", name) == 0) | ||||
return (CRYPTO_AES_CBC); | return (CRYPTO_AES_CBC); | ||||
else if (strcasecmp("aes-xts", name) == 0) | else if (strcasecmp("aes-xts", name) == 0) | ||||
return (CRYPTO_AES_XTS); | return (CRYPTO_AES_XTS); | ||||
else if (strcasecmp("blowfish", name) == 0) | |||||
return (CRYPTO_BLF_CBC); | |||||
else if (strcasecmp("blowfish-cbc", name) == 0) | |||||
return (CRYPTO_BLF_CBC); | |||||
else if (strcasecmp("camellia", name) == 0) | else if (strcasecmp("camellia", name) == 0) | ||||
return (CRYPTO_CAMELLIA_CBC); | return (CRYPTO_CAMELLIA_CBC); | ||||
else if (strcasecmp("camellia-cbc", name) == 0) | else if (strcasecmp("camellia-cbc", name) == 0) | ||||
return (CRYPTO_CAMELLIA_CBC); | return (CRYPTO_CAMELLIA_CBC); | ||||
else if (strcasecmp("3des", name) == 0) | |||||
return (CRYPTO_3DES_CBC); | |||||
else if (strcasecmp("3des-cbc", name) == 0) | |||||
return (CRYPTO_3DES_CBC); | |||||
return (CRYPTO_ALGORITHM_MIN - 1); | return (CRYPTO_ALGORITHM_MIN - 1); | ||||
} | } | ||||
static __inline u_int | static __inline u_int | ||||
g_eli_str2aalgo(const char *name) | g_eli_str2aalgo(const char *name) | ||||
{ | { | ||||
if (strcasecmp("hmac/md5", name) == 0) | if (strcasecmp("hmac/sha1", name) == 0) | ||||
return (CRYPTO_MD5_HMAC); | |||||
else if (strcasecmp("hmac/sha1", name) == 0) | |||||
return (CRYPTO_SHA1_HMAC); | return (CRYPTO_SHA1_HMAC); | ||||
else if (strcasecmp("hmac/ripemd160", name) == 0) | else if (strcasecmp("hmac/ripemd160", name) == 0) | ||||
return (CRYPTO_RIPEMD160_HMAC); | return (CRYPTO_RIPEMD160_HMAC); | ||||
else if (strcasecmp("hmac/sha256", name) == 0) | else if (strcasecmp("hmac/sha256", name) == 0) | ||||
return (CRYPTO_SHA2_256_HMAC); | return (CRYPTO_SHA2_256_HMAC); | ||||
else if (strcasecmp("hmac/sha384", name) == 0) | else if (strcasecmp("hmac/sha384", name) == 0) | ||||
return (CRYPTO_SHA2_384_HMAC); | return (CRYPTO_SHA2_384_HMAC); | ||||
else if (strcasecmp("hmac/sha512", name) == 0) | else if (strcasecmp("hmac/sha512", name) == 0) | ||||
return (CRYPTO_SHA2_512_HMAC); | return (CRYPTO_SHA2_512_HMAC); | ||||
return (CRYPTO_ALGORITHM_MIN - 1); | return (CRYPTO_ALGORITHM_MIN - 1); | ||||
} | } | ||||
static __inline const char * | static __inline const char * | ||||
g_eli_algo2str(u_int algo) | g_eli_algo2str(u_int algo) | ||||
{ | { | ||||
switch (algo) { | switch (algo) { | ||||
case CRYPTO_NULL_CBC: | case CRYPTO_NULL_CBC: | ||||
return ("NULL"); | return ("NULL"); | ||||
case CRYPTO_AES_CBC: | case CRYPTO_AES_CBC: | ||||
return ("AES-CBC"); | return ("AES-CBC"); | ||||
case CRYPTO_AES_XTS: | case CRYPTO_AES_XTS: | ||||
return ("AES-XTS"); | return ("AES-XTS"); | ||||
case CRYPTO_BLF_CBC: | |||||
return ("Blowfish-CBC"); | |||||
case CRYPTO_CAMELLIA_CBC: | case CRYPTO_CAMELLIA_CBC: | ||||
return ("CAMELLIA-CBC"); | return ("CAMELLIA-CBC"); | ||||
case CRYPTO_3DES_CBC: | |||||
return ("3DES-CBC"); | |||||
case CRYPTO_MD5_HMAC: | |||||
return ("HMAC/MD5"); | |||||
case CRYPTO_SHA1_HMAC: | case CRYPTO_SHA1_HMAC: | ||||
return ("HMAC/SHA1"); | return ("HMAC/SHA1"); | ||||
case CRYPTO_RIPEMD160_HMAC: | case CRYPTO_RIPEMD160_HMAC: | ||||
return ("HMAC/RIPEMD160"); | return ("HMAC/RIPEMD160"); | ||||
case CRYPTO_SHA2_256_HMAC: | case CRYPTO_SHA2_256_HMAC: | ||||
return ("HMAC/SHA256"); | return ("HMAC/SHA256"); | ||||
case CRYPTO_SHA2_384_HMAC: | case CRYPTO_SHA2_384_HMAC: | ||||
return ("HMAC/SHA384"); | return ("HMAC/SHA384"); | ||||
Show All 36 Lines | eli_metadata_dump(const struct g_eli_metadata *md) | ||||
bzero(str, sizeof(str)); | bzero(str, sizeof(str)); | ||||
for (i = 0; i < 16; i++) { | for (i = 0; i < 16; i++) { | ||||
str[i * 2] = hex[md->md_hash[i] >> 4]; | str[i * 2] = hex[md->md_hash[i] >> 4]; | ||||
str[i * 2 + 1] = hex[md->md_hash[i] & 0x0f]; | str[i * 2 + 1] = hex[md->md_hash[i] & 0x0f]; | ||||
} | } | ||||
printf(" MD5 hash: %s\n", str); | printf(" MD5 hash: %s\n", str); | ||||
} | } | ||||
#ifdef _KERNEL | |||||
static bool | |||||
eli_metadata_crypto_supported(const struct g_eli_metadata *md) | |||||
{ | |||||
switch (md->md_ealgo) { | |||||
case CRYPTO_NULL_CBC: | |||||
case CRYPTO_AES_CBC: | |||||
case CRYPTO_CAMELLIA_CBC: | |||||
case CRYPTO_AES_XTS: | |||||
break; | |||||
default: | |||||
return (false); | |||||
} | |||||
if (md->md_flags & G_ELI_FLAG_AUTH) { | |||||
switch (md->md_aalgo) { | |||||
case CRYPTO_SHA1_HMAC: | |||||
case CRYPTO_RIPEMD160_HMAC: | |||||
case CRYPTO_SHA2_256_HMAC: | |||||
case CRYPTO_SHA2_384_HMAC: | |||||
case CRYPTO_SHA2_512_HMAC: | |||||
break; | |||||
default: | |||||
return (false); | |||||
} | |||||
} | |||||
return (true); | |||||
} | |||||
#endif | |||||
static __inline u_int | static __inline u_int | ||||
g_eli_keylen(u_int algo, u_int keylen) | g_eli_keylen(u_int algo, u_int keylen) | ||||
{ | { | ||||
switch (algo) { | switch (algo) { | ||||
case CRYPTO_NULL_CBC: | case CRYPTO_NULL_CBC: | ||||
if (keylen == 0) | if (keylen == 0) | ||||
keylen = 64 * 8; | keylen = 64 * 8; | ||||
Show All 19 Lines | case CRYPTO_AES_XTS: | ||||
case 0: | case 0: | ||||
return (128); | return (128); | ||||
case 128: | case 128: | ||||
case 256: | case 256: | ||||
return (keylen); | return (keylen); | ||||
default: | default: | ||||
return (0); | return (0); | ||||
} | } | ||||
case CRYPTO_BLF_CBC: | |||||
if (keylen == 0) | |||||
return (128); | |||||
if (keylen < 128 || keylen > 448) | |||||
return (0); | |||||
if ((keylen % 32) != 0) | |||||
return (0); | |||||
return (keylen); | |||||
case CRYPTO_3DES_CBC: | |||||
if (keylen == 0 || keylen == 192) | |||||
return (192); | |||||
return (0); | |||||
default: | default: | ||||
return (0); | return (0); | ||||
} | } | ||||
} | } | ||||
static __inline u_int | static __inline u_int | ||||
g_eli_ivlen(u_int algo) | g_eli_ivlen(u_int algo) | ||||
{ | { | ||||
switch (algo) { | switch (algo) { | ||||
case CRYPTO_AES_XTS: | case CRYPTO_AES_XTS: | ||||
return (AES_XTS_IV_LEN); | return (AES_XTS_IV_LEN); | ||||
case CRYPTO_AES_CBC: | case CRYPTO_AES_CBC: | ||||
return (AES_BLOCK_LEN); | return (AES_BLOCK_LEN); | ||||
case CRYPTO_BLF_CBC: | |||||
return (BLOWFISH_BLOCK_LEN); | |||||
case CRYPTO_CAMELLIA_CBC: | case CRYPTO_CAMELLIA_CBC: | ||||
return (CAMELLIA_BLOCK_LEN); | return (CAMELLIA_BLOCK_LEN); | ||||
case CRYPTO_3DES_CBC: | |||||
return (DES3_BLOCK_LEN); | |||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
static __inline u_int | static __inline u_int | ||||
g_eli_hashlen(u_int algo) | g_eli_hashlen(u_int algo) | ||||
{ | { | ||||
switch (algo) { | switch (algo) { | ||||
case CRYPTO_MD5_HMAC: | |||||
return (16); | |||||
case CRYPTO_SHA1_HMAC: | case CRYPTO_SHA1_HMAC: | ||||
return (20); | return (20); | ||||
case CRYPTO_RIPEMD160_HMAC: | case CRYPTO_RIPEMD160_HMAC: | ||||
return (20); | return (20); | ||||
case CRYPTO_SHA2_256_HMAC: | case CRYPTO_SHA2_256_HMAC: | ||||
return (32); | return (32); | ||||
case CRYPTO_SHA2_384_HMAC: | case CRYPTO_SHA2_384_HMAC: | ||||
return (48); | return (48); | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |