Add #if DROPBEAR_RSA guards

Fixes building with DROPBEAR_RSA disabled.
Closes #197
This commit is contained in:
Matt Johnston 2022-11-28 21:12:23 +08:00
parent a4689e25ec
commit 36a0313263
3 changed files with 10 additions and 5 deletions

View File

@ -120,6 +120,7 @@ enum signkey_type signkey_type_from_name(const char* name, unsigned int namelen)
/* Special case for rsa-sha2-256. This could be generalised if more /* Special case for rsa-sha2-256. This could be generalised if more
signature names are added that aren't 1-1 with public key names */ signature names are added that aren't 1-1 with public key names */
const char* signature_name_from_type(enum signature_type type, unsigned int *namelen) { const char* signature_name_from_type(enum signature_type type, unsigned int *namelen) {
#if DROPBEAR_RSA
#if DROPBEAR_RSA_SHA256 #if DROPBEAR_RSA_SHA256
if (type == DROPBEAR_SIGNATURE_RSA_SHA256) { if (type == DROPBEAR_SIGNATURE_RSA_SHA256) {
if (namelen) { if (namelen) {
@ -136,11 +137,13 @@ const char* signature_name_from_type(enum signature_type type, unsigned int *nam
return SSH_SIGNKEY_RSA; return SSH_SIGNKEY_RSA;
} }
#endif #endif
#endif /* DROPBEAR_RSA */
return signkey_name_from_type((enum signkey_type)type, namelen); return signkey_name_from_type((enum signkey_type)type, namelen);
} }
/* Returns DROPBEAR_SIGNATURE_NONE if none match */ /* Returns DROPBEAR_SIGNATURE_NONE if none match */
enum signature_type signature_type_from_name(const char* name, unsigned int namelen) { enum signature_type signature_type_from_name(const char* name, unsigned int namelen) {
#if DROPBEAR_RSA
#if DROPBEAR_RSA_SHA256 #if DROPBEAR_RSA_SHA256
if (namelen == strlen(SSH_SIGNATURE_RSA_SHA256) if (namelen == strlen(SSH_SIGNATURE_RSA_SHA256)
&& memcmp(name, SSH_SIGNATURE_RSA_SHA256, namelen) == 0) { && memcmp(name, SSH_SIGNATURE_RSA_SHA256, namelen) == 0) {
@ -153,6 +156,7 @@ enum signature_type signature_type_from_name(const char* name, unsigned int name
return DROPBEAR_SIGNATURE_RSA_SHA1; return DROPBEAR_SIGNATURE_RSA_SHA1;
} }
#endif #endif
#endif /* DROPBEAR_RSA */
return (enum signature_type)signkey_type_from_name(name, namelen); return (enum signature_type)signkey_type_from_name(name, namelen);
} }
@ -167,6 +171,7 @@ enum signature_type signature_type_from_signkey(enum signkey_type keytype) {
} }
enum signkey_type signkey_type_from_signature(enum signature_type sigtype) { enum signkey_type signkey_type_from_signature(enum signature_type sigtype) {
#if DROPBEAR_RSA
#if DROPBEAR_RSA_SHA256 #if DROPBEAR_RSA_SHA256
if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA256) { if (sigtype == DROPBEAR_SIGNATURE_RSA_SHA256) {
return DROPBEAR_SIGNKEY_RSA; return DROPBEAR_SIGNKEY_RSA;
@ -177,6 +182,7 @@ enum signkey_type signkey_type_from_signature(enum signature_type sigtype) {
return DROPBEAR_SIGNKEY_RSA; return DROPBEAR_SIGNKEY_RSA;
} }
#endif #endif
#endif /* DROPBEAR_RSA */
assert((int)sigtype < (int)DROPBEAR_SIGNKEY_NUM_NAMED); assert((int)sigtype < (int)DROPBEAR_SIGNKEY_NUM_NAMED);
return (enum signkey_type)sigtype; return (enum signkey_type)sigtype;
} }

View File

@ -79,12 +79,14 @@ enum signature_type {
DROPBEAR_SIGNATURE_SK_ED25519 = DROPBEAR_SIGNKEY_SK_ED25519, DROPBEAR_SIGNATURE_SK_ED25519 = DROPBEAR_SIGNKEY_SK_ED25519,
#endif #endif
#endif #endif
#if DROPBEAR_RSA
#if DROPBEAR_RSA_SHA1 #if DROPBEAR_RSA_SHA1
DROPBEAR_SIGNATURE_RSA_SHA1 = 100, /* ssh-rsa signature (sha1) */ DROPBEAR_SIGNATURE_RSA_SHA1 = 100, /* ssh-rsa signature (sha1) */
#endif #endif
#if DROPBEAR_RSA_SHA256 #if DROPBEAR_RSA_SHA256
DROPBEAR_SIGNATURE_RSA_SHA256 = 101, /* rsa-sha2-256 signature. has a ssh-rsa key */ DROPBEAR_SIGNATURE_RSA_SHA256 = 101, /* rsa-sha2-256 signature. has a ssh-rsa key */
#endif #endif
#endif /* DROPBEAR_RSA */
DROPBEAR_SIGNATURE_NONE = DROPBEAR_SIGNKEY_NONE, DROPBEAR_SIGNATURE_NONE = DROPBEAR_SIGNKEY_NONE,
}; };

View File

@ -151,9 +151,6 @@
* signing operations slightly slower. */ * signing operations slightly slower. */
#define DROPBEAR_RSA_BLINDING 1 #define DROPBEAR_RSA_BLINDING 1
#ifndef DROPBEAR_RSA_SHA1
#define DROPBEAR_RSA_SHA1 DROPBEAR_RSA
#endif
#ifndef DROPBEAR_RSA_SHA256 #ifndef DROPBEAR_RSA_SHA256
#define DROPBEAR_RSA_SHA256 DROPBEAR_RSA #define DROPBEAR_RSA_SHA256 DROPBEAR_RSA
#endif #endif