Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
158 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis | ||
* | ||
* LibTomCrypt is a library that provides various cryptographic | ||
* algorithms in a highly modular and flexible manner. | ||
* | ||
* The library is free for all purposes without any express | ||
* guarantee it works. | ||
*/ | ||
#include "tomcrypt_private.h" | ||
|
||
/** | ||
@file rsa_key.c | ||
Free an RSA key, Tom St Denis | ||
Basic operations on an RSA key, Steffen Jaeckel | ||
*/ | ||
|
||
#ifdef LTC_MRSA | ||
#include <stdarg.h> | ||
|
||
static void _mpi_shrink_multi(void **a, ...) | ||
{ | ||
void **cur; | ||
unsigned n; | ||
int err; | ||
va_list args; | ||
void *tmp[10] = { 0 }; | ||
|
||
n = 0; | ||
err = CRYPT_ERROR; | ||
cur = a; | ||
va_start(args, a); | ||
while (cur != NULL) { | ||
if (n >= sizeof(tmp)/sizeof(tmp[0])) { | ||
goto out; | ||
} | ||
if (*cur != NULL) { | ||
if ((err = mp_init_copy(&tmp[n], *cur)) != CRYPT_OK) { | ||
goto out; | ||
} | ||
n++; | ||
} | ||
cur = va_arg(args, void**); | ||
} | ||
va_end(args); | ||
|
||
n = 0; | ||
cur = a; | ||
va_start(args, a); | ||
while (cur != NULL) { | ||
if (*cur != NULL) { | ||
mp_clear(*cur); | ||
*cur = tmp[n]; | ||
n++; | ||
} | ||
cur = va_arg(args, void**); | ||
} | ||
out: | ||
va_end(args); | ||
/* clean-up after an error | ||
* or after this was called with too many args | ||
*/ | ||
if ((err != CRYPT_OK) || | ||
(n >= sizeof(tmp)/sizeof(tmp[0]))) { | ||
for (n = 0; n < sizeof(tmp)/sizeof(tmp[0]); ++n) { | ||
if (tmp[n] != NULL) { | ||
mp_clear(tmp[n]); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
This shrinks the allocated memory of a RSA key | ||
It will use up some more memory temporarily, | ||
but then it will free-up the entire sequence that | ||
was once allocated when the key was created/populated. | ||
@param key The RSA key to shrink | ||
*/ | ||
void rsa_shrink_key(rsa_key *key) | ||
{ | ||
LTC_ARGCHKVD(key != NULL); | ||
_mpi_shrink_multi(&key->q, &key->p, &key->qP, &key->dP, &key->dQ, &key->N, &key->d, &key->e, NULL); | ||
} | ||
|
||
/** | ||
Init an RSA key | ||
@param key The RSA key to free | ||
@return CRYPT_OK if successful | ||
*/ | ||
int rsa_init(rsa_key *key) | ||
{ | ||
LTC_ARGCHK(key != NULL); | ||
return mp_init_multi(&key->e, &key->d, &key->N, &key->dQ, &key->dP, &key->qP, &key->p, &key->q, NULL); | ||
} | ||
|
||
/** | ||
Free an RSA key from memory | ||
@param key The RSA key to free | ||
*/ | ||
void rsa_free(rsa_key *key) | ||
{ | ||
LTC_ARGCHKVD(key != NULL); | ||
mp_cleanup_multi(&key->q, &key->p, &key->qP, &key->dP, &key->dQ, &key->N, &key->d, &key->e, NULL); | ||
} | ||
|
||
#endif | ||
|
||
/* ref: $Format:%D$ */ | ||
/* git commit: $Format:%H$ */ | ||
/* commit time: $Format:%ai$ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters