⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tomcrypt_pk.h

📁 该压缩包中包括 tom的加密函数库及pdf说明 ,以及Rinick s ECC:椭圆曲线非对称加密密钥生成器
💻 H
📖 第 1 页 / 共 2 页
字号:
/* ---- NUMBER THEORY ---- */#ifdef MPI#include "ltc_tommath.h"/* in/out macros */#define OUTPUT_BIGNUM(num, out, y, z)                                                             \{                                                                                                 \      if ((y + 4) > *outlen) { return CRYPT_BUFFER_OVERFLOW; }                                    \      z = (unsigned long)mp_unsigned_bin_size(num);                                               \      STORE32L(z, out+y);                                                                         \      y += 4;                                                                                     \      if ((y + z) > *outlen) { return CRYPT_BUFFER_OVERFLOW; }                                    \      if ((err = mp_to_unsigned_bin(num, out+y)) != MP_OKAY) { return mpi_to_ltc_error(err); }    \      y += z;                                                                                     \}#define INPUT_BIGNUM(num, in, x, y, inlen)                       \{                                                                \     /* load value */                                            \     if ((y + 4) > inlen) {                                      \        err = CRYPT_INVALID_PACKET;                              \        goto error;                                              \     }                                                           \     LOAD32L(x, in+y);                                           \     y += 4;                                                     \                                                                 \     /* sanity check... */                                       \     if ((x+y) > inlen) {                                        \        err = CRYPT_INVALID_PACKET;                              \        goto error;                                              \     }                                                           \                                                                 \     /* load it */                                               \     if ((err = mp_read_unsigned_bin(num, (unsigned char *)in+y, (int)x)) != MP_OKAY) {\        err = mpi_to_ltc_error(err);                             \        goto error;                                              \     }                                                           \     y += x;                                                     \     if ((err = mp_shrink(num)) != MP_OKAY) {                    \        err = mpi_to_ltc_error(err);                             \        goto error;                                              \     }                                                           \} int is_prime(mp_int *, int *); int rand_prime(mp_int *N, long len, prng_state *prng, int wprng);#else   #ifdef MRSA      #error RSA requires the big int library    #endif   #ifdef MECC      #error ECC requires the big int library    #endif   #ifdef MDH      #error DH requires the big int library    #endif   #ifdef MDSA      #error DSA requires the big int library    #endif#endif /* MPI *//* ---- PUBLIC KEY CRYPTO ---- */#define PK_PRIVATE            0        /* PK private keys */#define PK_PUBLIC             1        /* PK public keys *//* ---- PACKET ---- */#ifdef PACKETvoid packet_store_header(unsigned char *dst, int section, int subsection);int packet_valid_header(unsigned char *src, int section, int subsection);#endif/* ---- RSA ---- */#ifdef MRSA/* Min and Max RSA key sizes (in bits) */#define MIN_RSA_SIZE 1024#define MAX_RSA_SIZE 4096typedef struct Rsa_key {    int type;    mp_int e, d, N, p, q, qP, dP, dQ;} rsa_key;int rsa_make_key(prng_state *prng, int wprng, int size, long e, rsa_key *key);int rsa_exptmod(const unsigned char *in,   unsigned long inlen,                      unsigned char *out,  unsigned long *outlen, int which,                      rsa_key *key);void rsa_free(rsa_key *key);/* These use PKCS #1 v2.0 padding */int rsa_encrypt_key(const unsigned char *in,     unsigned long inlen,                          unsigned char *out,    unsigned long *outlen,                    const unsigned char *lparam, unsigned long lparamlen,                    prng_state *prng, int prng_idx, int hash_idx, rsa_key *key);                                        int rsa_decrypt_key(const unsigned char *in,       unsigned long inlen,                          unsigned char *out,      unsigned long *outlen,                     const unsigned char *lparam,   unsigned long lparamlen,                          int            hash_idx, int *stat,                          rsa_key       *key);int rsa_sign_hash(const unsigned char *in,     unsigned long  inlen,                         unsigned char *out,    unsigned long *outlen,                         prng_state    *prng,     int            prng_idx,                        int            hash_idx, unsigned long  saltlen,                        rsa_key *key);int rsa_verify_hash(const unsigned char *sig,      unsigned long siglen,                    const unsigned char *hash,     unsigned long hashlen,                          int            hash_idx, unsigned long saltlen,                          int           *stat,     rsa_key      *key);/* PKCS #1 import/export */int rsa_export(unsigned char *out, unsigned long *outlen, int type, rsa_key *key);int rsa_import(const unsigned char *in, unsigned long inlen, rsa_key *key);                        #endif/* ---- DH Routines ---- */#ifdef MDH typedef struct Dh_key {    int idx, type;    mp_int x, y;} dh_key;int dh_test(void);void dh_sizes(int *low, int *high);int dh_get_size(dh_key *key);int dh_make_key(prng_state *prng, int wprng, int keysize, dh_key *key);void dh_free(dh_key *key);int dh_export(unsigned char *out, unsigned long *outlen, int type, dh_key *key);int dh_import(const unsigned char *in, unsigned long inlen, dh_key *key);int dh_shared_secret(dh_key        *private_key, dh_key        *public_key,                     unsigned char *out,         unsigned long *outlen);int dh_encrypt_key(const unsigned char *in,    unsigned long  keylen,                         unsigned char *out,   unsigned long *outlen,                          prng_state    *prng,  int wprng, int hash,                          dh_key        *key);int dh_decrypt_key(const unsigned char *in,  unsigned long  inlen,                          unsigned char *out, unsigned long *outlen,                          dh_key *key);int dh_sign_hash(const unsigned char *in,   unsigned long inlen,                       unsigned char *out,  unsigned long *outlen,                       prng_state    *prng, int wprng, dh_key *key);int dh_verify_hash(const unsigned char *sig,  unsigned long siglen,                   const unsigned char *hash, unsigned long hashlen,                    int *stat, dh_key *key);#endif/* ---- ECC Routines ---- */#ifdef MECC/** Structure defines a NIST GF(p) curve */typedef struct {   /** The size of the curve in octets */   int size;   /** name of curve */   char *name;    /** The prime that defines the field the curve is in (encoded in base-64) */   char *prime;   /** The fields B param (base64) */   char *B;   /** The order of the curve (base64) */   char *order;     /** The x co-ordinate of the base point on the curve (base64) */   char *Gx;    /** The y co-ordinate of the base point on the curve (base64) */   char *Gy;} ltc_ecc_set_type;/** A point on a ECC curve, stored in Jacbobian format such that (x,y,z) => (x/z^2, y/z^3, 1) when interpretted as affine */typedef struct {    /** The x co-ordinate */    mp_int x;    /** The y co-ordinate */    mp_int y;    /** The z co-ordinate */    mp_int z;} ecc_point;/** An ECC key */typedef struct {    /** Type of key, PK_PRIVATE or PK_PUBLIC */    int type;    /** Index into the ltc_ecc_sets[] for the parameters of this curve */    int idx;    /** The public key */    ecc_point pubkey;    /** The private key */    mp_int k;} ecc_key;/** the ECC params provided */extern const ltc_ecc_set_type ecc_sets[];int ecc_test(void);void ecc_sizes(int *low, int *high);int ecc_get_size(ecc_key *key);int ecc_make_key(prng_state *prng, int wprng, int keysize, ecc_key *key);void ecc_free(ecc_key *key);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -