summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <sreeharsha@totakura.in>2015-01-22 16:22:32 +0100
committerSree Harsha Totakura <sreeharsha@totakura.in>2015-01-22 16:22:32 +0100
commitb119131873822fa50fbe94d1a09132fa31d3bc3a (patch)
tree4fc859f152b6baec9978dd7a2202044b81323a23 /src
parentce9da7f183f5f00b99e460b171291d6a028c53f2 (diff)
downloadexchange-b119131873822fa50fbe94d1a09132fa31d3bc3a.tar.gz
exchange-b119131873822fa50fbe94d1a09132fa31d3bc3a.tar.bz2
exchange-b119131873822fa50fbe94d1a09132fa31d3bc3a.zip
Remove TALER_RSA_hash_sign() and TALER_RSA_hash_verify().
Diffstat (limited to 'src')
-rw-r--r--src/include/taler_rsa.h20
-rw-r--r--src/util/rsa.c62
-rw-r--r--src/util/test_rsa.c12
3 files changed, 34 insertions, 60 deletions
diff --git a/src/include/taler_rsa.h b/src/include/taler_rsa.h
index 1d263ae09..98be63372 100644
--- a/src/include/taler_rsa.h
+++ b/src/include/taler_rsa.h
@@ -229,7 +229,8 @@ TALER_RSA_public_key_from_string (const char *enc,
/**
- * Sign a given block.h
+ * Sign a given data block. The size of the message should be less than
+ * TALER_RSA_DATA_ENCODING_LENGTH (256) bytes.
*
* @param key private key to use for the signing
* @param msg the message
@@ -245,21 +246,8 @@ TALER_RSA_sign (const struct TALER_RSA_PrivateKey *key,
/**
- * Verify signature with the given hash.
- *
- * @param hash the hash code to verify against the signature
- * @param sig signature that is being validated
- * @param publicKey public key of the signer
- * @returns GNUNET_OK if ok, GNUNET_SYSERR if invalid
- */
-int
-TALER_RSA_hash_verify (const struct GNUNET_HashCode *hash,
- const struct TALER_RSA_Signature *sig,
- const struct TALER_RSA_PublicKeyBinaryEncoded *publicKey);
-
-
-/**
- * Verify signature on the given message
+ * Verify signature on the given message. The size of the message should be
+ * less than TALER_RSA_DATA_ENCODING_LENGTH (256) bytes.
*
* @param msg the message
* @param size the size of the message
diff --git a/src/util/rsa.c b/src/util/rsa.c
index c34ab1661..0b533615c 100644
--- a/src/util/rsa.c
+++ b/src/util/rsa.c
@@ -578,18 +578,19 @@ data_to_sexp (const void *ptr, size_t size)
/**
- * Sign the given hash block.
+ * Sign the given message. The size of the message should be less than
+ * TALER_RSA_DATA_ENCODING_LENGTH (256) bytes.
*
* @param key private key to use for the signing
- * @param hash the block containing the hash of the message to sign
- * @param hash_size the size of the hash block
+ * @param msg the message
+ * @param size the size of the message
* @param sig where to write the signature
* @return GNUNET_SYSERR on error, GNUNET_OK on success
*/
int
TALER_RSA_sign (const struct TALER_RSA_PrivateKey *key,
- const void *hash,
- size_t hash_size,
+ const void *msg,
+ size_t size,
struct TALER_RSA_Signature *sig)
{
gcry_sexp_t result;
@@ -597,7 +598,10 @@ TALER_RSA_sign (const struct TALER_RSA_PrivateKey *key,
size_t ssize;
gcry_mpi_t rval;
- data = data_to_sexp (hash, hash_size);
+ GNUNET_assert (size <= TALER_RSA_DATA_ENCODING_LENGTH);
+ if (size > TALER_RSA_DATA_ENCODING_LENGTH)
+ return GNUNET_SYSERR;
+ data = data_to_sexp (msg, size);
GNUNET_assert (0 == gcry_pk_sign (&result, data, key->sexp));
gcry_sexp_release (data);
GNUNET_assert (0 == key_from_sexp (&rval, result, "rsa", "s"));
@@ -666,35 +670,42 @@ decode_public_key (const struct TALER_RSA_PublicKeyBinaryEncoded *publicKey)
/**
- * Verify signature with the given hash.
+ * Verify signature on the given message. The size of the message should be less than
+ * TALER_RSA_DATA_ENCODING_LENGTH (256) bytes.
*
- * @param hash the hash code to verify against the signature
+ * @param msg the message
+ * @param size the size of the message
* @param sig signature that is being validated
* @param publicKey public key of the signer
* @returns GNUNET_OK if ok, GNUNET_SYSERR if invalid
*/
int
-TALER_RSA_hash_verify (const struct GNUNET_HashCode *hash,
- const struct TALER_RSA_Signature *sig,
- const struct TALER_RSA_PublicKeyBinaryEncoded *publicKey)
+TALER_RSA_verify (const void *msg, size_t size,
+ const struct TALER_RSA_Signature *sig,
+ const struct TALER_RSA_PublicKeyBinaryEncoded *publicKey)
{
gcry_sexp_t data;
gcry_sexp_t sigdata;
- size_t size;
+ size_t sig_size;
gcry_mpi_t val;
gcry_sexp_t psexp;
size_t erroff;
int rc;
- size = sizeof (struct TALER_RSA_Signature);
+ GNUNET_assert (size <= TALER_RSA_DATA_ENCODING_LENGTH);
+ if (size > TALER_RSA_DATA_ENCODING_LENGTH)
+ return GNUNET_SYSERR;
GNUNET_assert (0 ==
gcry_mpi_scan (&val, GCRYMPI_FMT_USG,
- (const unsigned char *) sig, size, &size));
+ (const unsigned char *) sig,
+ sizeof (struct TALER_RSA_Signature),
+ &sig_size));
+ GNUNET_assert (sizeof (struct TALER_RSA_Signature) == sig_size);
GNUNET_assert (0 ==
gcry_sexp_build (&sigdata, &erroff, "(sig-val(rsa(s %m)))",
val));
gcry_mpi_release (val);
- data = data_to_sexp (hash, sizeof (struct GNUNET_HashCode));
+ data = data_to_sexp (msg, size);
if (! (psexp = decode_public_key (publicKey)))
{
gcry_sexp_release (data);
@@ -715,27 +726,6 @@ TALER_RSA_hash_verify (const struct GNUNET_HashCode *hash,
return GNUNET_OK;
}
-
-/**
- * Verify signature on the given message
- *
- * @param msg the message
- * @param size the size of the message
- * @param sig signature that is being validated
- * @param publicKey public key of the signer
- * @returns GNUNET_OK if ok, GNUNET_SYSERR if invalid
- */
-int
-TALER_RSA_verify (const void *msg, size_t size,
- const struct TALER_RSA_Signature *sig,
- const struct TALER_RSA_PublicKeyBinaryEncoded *publicKey)
-{
- struct GNUNET_HashCode hash;
-
- GNUNET_CRYPTO_hash (msg, size, &hash);
- return TALER_RSA_hash_verify (&hash, sig, publicKey);
-}
-
/**
* The blinding key is equal in length to the RSA modulus
*/
diff --git a/src/util/test_rsa.c b/src/util/test_rsa.c
index 85114843d..1f7adfd6c 100644
--- a/src/util/test_rsa.c
+++ b/src/util/test_rsa.c
@@ -69,11 +69,7 @@ main (int argc, char *argv[])
ntohs (priv_enc->len))));
GNUNET_free (priv_enc);
priv_enc = NULL;
- EXITIF (GNUNET_OK != TALER_RSA_hash_verify (&hash,
- &sig,
- &pubkey));
- EXITIF (GNUNET_OK != TALER_RSA_verify (rnd_blk,
- RND_BLK_SIZE,
+ EXITIF (GNUNET_OK != TALER_RSA_verify (&hash, sizeof (hash),
&sig,
&pubkey));
@@ -93,9 +89,9 @@ main (int argc, char *argv[])
EXITIF (GNUNET_OK != TALER_RSA_unblind (&sig,
bkey,
&pubkey));
- EXITIF (GNUNET_OK != TALER_RSA_hash_verify (&hash,
- &sig,
- &pubkey));
+ EXITIF (GNUNET_OK != TALER_RSA_verify (&hash, sizeof (hash),
+ &sig,
+ &pubkey));
ret = 0; /* all OK */
EXITIF_exit: