Revert "Imported upstream version 1.6.7"
[platform/upstream/cryptsetup.git] / lib / crypto_backend / crypto_nettle.c
index 4422a68..21820d9 100644 (file)
@@ -1,19 +1,21 @@
 /*
  * Nettle crypto backend implementation
  *
- * Copyright (C) 2011 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2011-2012 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2011-2012, Milan Broz
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * This file 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.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
@@ -24,6 +26,8 @@
 #include <nettle/hmac.h>
 #include "crypto_backend.h"
 
+static char *version = "Nettle";
+
 typedef void (*init_func) (void *);
 typedef void (*update_func) (void *, unsigned, const uint8_t *);
 typedef void (*digest_func) (void *, unsigned, uint8_t *);
@@ -135,10 +139,14 @@ static struct hash_alg *_get_alg(const char *name)
 
 int crypt_backend_init(struct crypt_device *ctx)
 {
-       log_dbg("Initialising Nettle crypto backend.");
        return 0;
 }
 
+const char *crypt_backend_version(void)
+{
+       return version;
+}
+
 /* HASH */
 int crypt_hash_size(const char *name)
 {
@@ -262,3 +270,24 @@ int crypt_hmac_destroy(struct crypt_hmac *ctx)
        free(ctx);
        return 0;
 }
+
+/* RNG - N/A */
+int crypt_backend_rng(char *buffer, size_t length, int quality, int fips)
+{
+       return -EINVAL;
+}
+
+/* PBKDF */
+int crypt_pbkdf(const char *kdf, const char *hash,
+               const char *password, size_t password_length,
+               const char *salt, size_t salt_length,
+               char *key, size_t key_length,
+               unsigned int iterations)
+{
+       if (!kdf || strncmp(kdf, "pbkdf2", 6))
+               return -EINVAL;
+
+       /* FIXME: switch to internal implementation in Nettle 2.6 */
+       return pkcs5_pbkdf2(hash, password, password_length, salt, salt_length,
+                           iterations, key_length, key);
+}