summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMilan Broz <gmazyland@gmail.com>2010-10-26 14:34:47 +0000
committerMilan Broz <gmazyland@gmail.com>2010-10-26 14:34:47 +0000
commitbb8e0853786f0430cbe28b6c9909b42d251c7bb3 (patch)
tree1fdc0b31bfcf326083d0f0a148873a2fdc5970c5 /lib
parent3b50005d2f7f7e802d3011e68a7290d374ae3afb (diff)
downloadcryptsetup-bb8e0853786f0430cbe28b6c9909b42d251c7bb3.tar.gz
cryptsetup-bb8e0853786f0430cbe28b6c9909b42d251c7bb3.tar.bz2
cryptsetup-bb8e0853786f0430cbe28b6c9909b42d251c7bb3.zip
Add utils_crypt file and test for supported modes presentation.
git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@348 36d66b0a-2a48-0410-832c-cd162a569da5
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am2
-rw-r--r--lib/internal.h5
-rw-r--r--lib/setup.c27
-rw-r--r--lib/utils_crypt.c42
-rw-r--r--lib/utils_crypt.h9
5 files changed, 55 insertions, 30 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index be97c0b..c950377 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -38,6 +38,8 @@ libcryptsetup_la_SOURCES = \
blockdev.h \
libcryptsetup.h \
utils.c \
+ utils_crypt.c \
+ utils_crypt.h \
utils_debug.c \
backends.c \
libdevmapper.c \
diff --git a/lib/internal.h b/lib/internal.h
index 8e445f6..a06d558 100644
--- a/lib/internal.h
+++ b/lib/internal.h
@@ -11,6 +11,7 @@
#include <inttypes.h>
#include "nls.h"
+#include "utils_crypt.h"
#define SECTOR_SHIFT 9
#define SECTOR_SIZE (1 << SECTOR_SHIFT)
@@ -73,8 +74,6 @@ int hash(const char *backend_name, const char *hash_name,
char *result, size_t size,
const char *passphrase, size_t sizep);
-void hexprint(char *d, int n);
-
/* Device mapper backend */
const char *dm_get_dir(void);
int dm_init(struct crypt_device *context, int check_kernel);
@@ -114,8 +113,6 @@ void get_key(char *prompt, char **key, unsigned int *passLen, int key_size,
const char *key_file, int timeout, int how2verify,
struct crypt_device *cd);
-int parse_into_name_and_mode(const char *nameAndMode, char *name, char *mode);
-
void logger(struct crypt_device *cd, int class, const char *file, int line, const char *format, ...);
#define log_dbg(x...) logger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
#define log_std(c, x...) logger(c, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
diff --git a/lib/setup.c b/lib/setup.c
index 444f4ec..6da952f 100644
--- a/lib/setup.c
+++ b/lib/setup.c
@@ -126,31 +126,6 @@ static char *process_key(struct crypt_device *cd, const char *hash_name,
return key;
}
-int parse_into_name_and_mode(const char *nameAndMode, char *name, char *mode)
-{
-/* Token content stringification, see info cpp/stringification */
-#define str(s) #s
-#define xstr(s) str(s)
-#define scanpattern1 "%" xstr(LUKS_CIPHERNAME_L) "[^-]-%" xstr(LUKS_CIPHERMODE_L) "s"
-#define scanpattern2 "%" xstr(LUKS_CIPHERNAME_L) "[^-]"
-
- int r;
-
- if(sscanf(nameAndMode,scanpattern1, name, mode) != 2) {
- if((r = sscanf(nameAndMode,scanpattern2,name)) == 1)
- strncpy(mode,"cbc-plain",10);
- else
- return -EINVAL;
- }
-
- return 0;
-
-#undef scanpattern1
-#undef scanpattern2
-#undef str
-#undef xstr
-}
-
static int isPLAIN(const char *type)
{
return (type && !strcmp(CRYPT_PLAIN, type));
@@ -751,7 +726,7 @@ int crypt_luksFormat(struct crypt_options *options)
};
int r;
- r = parse_into_name_and_mode(options->cipher, cipherName, cipherMode);
+ r = crypt_parse_name_and_mode(options->cipher, cipherName, cipherMode);
if(r < 0) {
log_err(cd, _("No known cipher specification pattern detected.\n"));
return r;
diff --git a/lib/utils_crypt.c b/lib/utils_crypt.c
new file mode 100644
index 0000000..0c47fa2
--- /dev/null
+++ b/lib/utils_crypt.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include "internal.h"
+
+int crypt_parse_name_and_mode(const char *s, char *cipher, char *cipher_mode)
+{
+ if (sscanf(s, "%" MAX_CIPHER_LEN_STR "[^-]-%" MAX_CIPHER_LEN_STR "s",
+ cipher, cipher_mode) == 2) {
+ return 0;
+ }
+
+ if (sscanf(s, "%" MAX_CIPHER_LEN_STR "[^-]", cipher) == 1) {
+ strncpy(cipher_mode, "cbc-plain", 9);
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
+#if 0
+/* Token content stringification, see info cpp/stringification */
+#define str(s) #s
+#define xstr(s) str(s)
+#define scanpattern1 "%" xstr(MAX_CIPHER_LEN) "[^-]-%" xstr(MAX_CIPHER_LEN) "s"
+#define scanpattern2 "%" xstr(MAX_CIPHER_LEN) "[^-]"
+
+ if(sscanf(nameAndMode,scanpattern1, name, mode) != 2) {
+ if((r = sscanf(nameAndMode,scanpattern2,name)) == 1)
+ strncpy(mode,"cbc-plain",10);
+ else
+ return -EINVAL;
+ }
+
+ return 0;
+
+#undef scanpattern1
+#undef scanpattern2
+#undef str
+#undef xstr
+#endif
diff --git a/lib/utils_crypt.h b/lib/utils_crypt.h
new file mode 100644
index 0000000..10ed36e
--- /dev/null
+++ b/lib/utils_crypt.h
@@ -0,0 +1,9 @@
+#ifndef _UTILS_CRYPT_H
+#define _UTILS_CRYPT_H
+
+#define MAX_CIPHER_LEN 32
+#define MAX_CIPHER_LEN_STR "32"
+
+int crypt_parse_name_and_mode(const char *s, char *cipher, char *cipher_mode);
+
+#endif /* _UTILS_CRYPT_H */