Path: blob/master/libs/tomcrypt/src/pk/pkcs1/pkcs_1_i2osp.c
4396 views
/* LibTomCrypt, modular cryptographic library -- Tom St Denis1*2* LibTomCrypt is a library that provides various cryptographic3* algorithms in a highly modular and flexible manner.4*5* The library is free for all purposes without any express6* guarantee it works.7*/8#include "tomcrypt.h"910/**11@file pkcs_1_i2osp.c12Integer to Octet I2OSP, Tom St Denis13*/1415#ifdef LTC_PKCS_11617/* always stores the same # of bytes, pads with leading zero bytes18as required19*/2021/**22PKCS #1 Integer to binary23@param n The integer to store24@param modulus_len The length of the RSA modulus25@param out [out] The destination for the integer26@return CRYPT_OK if successful27*/28int pkcs_1_i2osp(void *n, unsigned long modulus_len, unsigned char *out)29{30unsigned long size;3132size = mp_unsigned_bin_size(n);3334if (size > modulus_len) {35return CRYPT_BUFFER_OVERFLOW;36}3738/* store it */39zeromem(out, modulus_len);40return mp_to_unsigned_bin(n, out+(modulus_len-size));41}4243#endif /* LTC_PKCS_1 */444546