Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Unified Diff: src/platform/vboot_reference/crypto/rsa_utility.c

Issue 575019: Add some convenience/helper functions for RSA. (Closed)
Patch Set: Add comment to size calculation. Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/platform/vboot_reference/crypto/rsa_utility.c
diff --git a/src/platform/vboot_reference/crypto/rsa_utility.c b/src/platform/vboot_reference/crypto/rsa_utility.c
new file mode 100644
index 0000000000000000000000000000000000000000..2215b7cec220181b2102ae702fcf26758bfbaeaf
--- /dev/null
+++ b/src/platform/vboot_reference/crypto/rsa_utility.c
@@ -0,0 +1,46 @@
+/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Utility functions for message digest functions.
+ */
+
+#include "padding.h"
+#include "rsa_utility.h"
+#include "utility.h"
+
+int RSAProcessedKeySize(int algorithm) {
+ int key_len = siglen_map[algorithm] * sizeof(uint32_t); /* Key length in
+ * bytes. */
+ /* Total size needed by a RSAPublicKey structure is =
+ * 2 * key_len bytes for the n and rr arrays
+ * + sizeof len + sizeof n0inv.
+ */
+ return (2 * key_len + sizeof(int) + sizeof(uint32_t));
+}
+
+RSAPublicKey* RSAPublicKeyFromBuf(uint8_t* buf, int len) {
+ RSAPublicKey* key = (RSAPublicKey*) Malloc(sizeof(RSAPublicKey));
+ MemcpyState st;
+ int key_len;
+
+ st.remaining_buf = buf;
+ st.remaining_len = len;
+
+ StatefulMemcpy(&st, &key->len, sizeof(key->len));
+ key_len = key->len * sizeof(uint32_t); /* key length in bytes. */
+ key->n = (uint32_t*) Malloc(key_len);
+ key->rr = (uint32_t*) Malloc(key_len);
+
+ StatefulMemcpy(&st, &key->n0inv, sizeof(key->n0inv));
+ StatefulMemcpy(&st, key->n, key_len);
+ StatefulMemcpy(&st, key->rr, key_len);
+ if (st.remaining_len != 0) { /* Underrun or overrun. */
+ Free(key->n);
+ Free(key->rr);
+ Free(key);
+ return NULL;
+ }
+
+ return key;
+}

Powered by Google App Engine
This is Rietveld 408576698