Codebase list libcryptx-perl / cdb83ee
ltc sync Karel Miko 6 years ago
11 changed file(s) with 36 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
2626
2727 /* version */
2828 #define CRYPT 0x0118
29 #define SCRYPT "1.18.0-rc2"
29 #define SCRYPT "1.18.0-rc3"
3030
3131 /* max size of either a cipher/hash block or symmetric key [largest of the two] */
3232 #define MAXBLOCKSIZE 128
1919 #define NORETURN
2020 #endif
2121
22 void crypt_argchk(char *v, char *s, int d) NORETURN;
22 void crypt_argchk(const char *v, const char *s, int d) NORETURN;
2323 #define LTC_ARGCHK(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
2424 #define LTC_ARGCHKVD(x) do { if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } }while(0)
2525
348348 /** cipher descriptor table, last entry has "name == NULL" to mark the end of table */
349349 extern struct ltc_cipher_descriptor {
350350 /** name of cipher */
351 char *name;
351 const char *name;
352352 /** internal ID */
353353 unsigned char ID;
354354 /** min keysize (octets) */
498498 /** Accelerated GCM packet (one shot)
499499 @param key The secret key
500500 @param keylen The length of the secret key
501 @param IV The initial vector
502 @param IVlen The length of the initial vector
501 @param IV The initialization vector
502 @param IVlen The length of the initialization vector
503503 @param adata The additional authentication data (header)
504504 @param adatalen The length of the adata
505505 @param pt The plaintext
527527 #if defined(LTC_MECC) || defined(LTC_MRSA) || defined(LTC_MDSA) || defined(LTC_MKAT)
528528 /* Include the MPI functionality? (required by the PK algorithms) */
529529 #define LTC_MPI
530
531 #ifndef LTC_PK_MAX_RETRIES
532 /* iterations limit for retry-loops */
533 #define LTC_PK_MAX_RETRIES 20
534 #endif
530535 #endif
531536
532537 #ifdef LTC_MRSA
203203 /** hash descriptor */
204204 extern struct ltc_hash_descriptor {
205205 /** name of hash */
206 char *name;
206 const char *name;
207207 /** internal ID */
208208 unsigned char ID;
209209 /** Size of digest in octets */
3434 /** math descriptor */
3535 typedef struct {
3636 /** Name of the math provider */
37 char *name;
37 const char *name;
3838
3939 /** Bits per digit, amount of bits must fit in an unsigned long */
4040 int bits_per_digit;
1818 /* Indicates standard output formats that can be read e.g. by OpenSSL or GnuTLS */
1919 #define PK_STD 0x1000
2020
21 /* iterations limit for retry-loops */
22 #define PK_MAX_RETRIES 20
23
2421 int rand_prime(void *N, long len, prng_state *prng, int wprng);
2522
23 #ifdef LTC_SOURCE
24 /* internal helper functions */
2625 int rand_bn_bits(void *N, int bits, prng_state *prng, int wprng);
2726 int rand_bn_upto(void *N, void *limit, prng_state *prng, int wprng);
2827
4039 } oid_st;
4140
4241 int pk_get_oid(int pk, oid_st *st);
42 #endif /* LTC_SOURCE */
4343
4444 /* ---- RSA ---- */
4545 #ifdef LTC_MRSA
199199 #ifdef LTC_MDH
200200
201201 typedef struct {
202 int size;
203 char *name, *base, *prime;
204 } ltc_dh_set_type;
205
206 extern const ltc_dh_set_type ltc_dh_sets[];
207
208 typedef struct {
209202 int type;
210203 void *x;
211204 void *y;
235228 int dh_export_key(void *out, unsigned long *outlen, int type, dh_key *key);
236229
237230 #ifdef LTC_SOURCE
231 typedef struct {
232 int size;
233 const char *name, *base, *prime;
234 } ltc_dh_set_type;
235
236 extern const ltc_dh_set_type ltc_dh_sets[];
237
238238 /* internal helper functions */
239239 int dh_check_pubkey(dh_key *key);
240240 #endif
257257 int size;
258258
259259 /** name of curve */
260 char *name;
260 const char *name;
261261
262262 /** The prime that defines the field the curve is in (encoded in hex) */
263 char *prime;
263 const char *prime;
264264
265265 /** The fields A param (hex) */
266 char *A;
266 const char *A;
267267
268268 /** The fields B param (hex) */
269 char *B;
269 const char *B;
270270
271271 /** The order of the curve (hex) */
272 char *order;
272 const char *order;
273273
274274 /** The x co-ordinate of the base point on the curve (hex) */
275 char *Gx;
275 const char *Gx;
276276
277277 /** The y co-ordinate of the base point on the curve (hex) */
278 char *Gy;
278 const char *Gy;
279279
280280 /** The co-factor */
281281 unsigned long cofactor;
7979 /* ===> PKCS #5 -- Password Based Cryptography <=== */
8080 #ifdef LTC_PKCS_5
8181
82 /* Algorithm #1 (old) */
82 /* Algorithm #1 (PBKDF1) */
8383 int pkcs_5_alg1(const unsigned char *password, unsigned long password_len,
8484 const unsigned char *salt,
8585 int iteration_count, int hash_idx,
8686 unsigned char *out, unsigned long *outlen);
8787
88 /* Algorithm #1 - OpenSSL-compatible variant for arbitrarily-long keys.
88 /* Algorithm #1 (PBKDF1) - OpenSSL-compatible variant for arbitrarily-long keys.
8989 Compatible with EVP_BytesToKey() */
9090 int pkcs_5_alg1_openssl(const unsigned char *password,
9191 unsigned long password_len,
9393 int iteration_count, int hash_idx,
9494 unsigned char *out, unsigned long *outlen);
9595
96 /* Algorithm #2 (new) */
96 /* Algorithm #2 (PBKDF2) */
9797 int pkcs_5_alg2(const unsigned char *password, unsigned long password_len,
9898 const unsigned char *salt, unsigned long salt_len,
9999 int iteration_count, int hash_idx,
8080 /** PRNG descriptor */
8181 extern struct ltc_prng_descriptor {
8282 /** Name of the PRNG */
83 char *name;
83 const char *name;
8484 /** size in bytes of exported state */
8585 int export_size;
8686 /** Start a PRNG state
4545 {
4646 unsigned char *buf;
4747 unsigned long keysize;
48 int err, max_iterations = PK_MAX_RETRIES;
48 int err, max_iterations = LTC_PK_MAX_RETRIES;
4949
5050 LTC_ARGCHK(key != NULL);
5151 LTC_ARGCHK(ltc_mp.name != NULL);
2222 @param hash The hash that was signed
2323 @param hashlen The length of the hash that was signed
2424 @param stat [out] The result of the signature verification, 1==valid, 0==invalid
25 @param key The corresponding public DH key
25 @param key The corresponding public DSA key
2626 @return CRYPT_OK if successful (even if the signature is invalid)
2727 */
2828 int dsa_verify_hash_raw( void *r, void *s,
8888 @param hash The hash that was signed
8989 @param hashlen The length of the hash that was signed
9090 @param stat [out] The result of the signature verification, 1==valid, 0==invalid
91 @param key The corresponding public DH key
91 @param key The corresponding public DSA key
9292 @return CRYPT_OK if successful (even if the signature is invalid)
9393 */
9494 int dsa_verify_hash(const unsigned char *sig, unsigned long siglen,