📄 jmrsa.h
字号:
/* $Id: jmrsa.h,v 1.5 2000/04/06 07:26:53 jm Exp $ * Core RSA functions * * Dynamic hierarchial IP tunnel * Copyright (C) 1998-2000, Dynamics group * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. See README and COPYING for * more details. */#ifndef JMRSA_H#define JMRSA_H#ifdef HAVE_CONFIG_H#include <config.h>#endif #if HAVE_GMP_H#include <gmp.h>#elif HAVE_GMP2_GMP_H#include <gmp2/gmp.h>#else#error "No gmp2 header file"#endiftypedef struct { mpz_t n; /* public modulus */ mpz_t e; /* public exponent */ mpz_t d; /* private exponent */ mpz_t p; /* prime p */ mpz_t q; /* prime q */ mpz_t u; /* p^-1 mod q */ mpz_t dp; /* d mod p-1 */ mpz_t dq; /* d mod q-1 */} rsa_secret_key;typedef struct { mpz_t n; /* public modulus */ mpz_t e; /* public exponent */} rsa_public_key;void rsa_encrypt(rsa_public_key *pub, mpz_t in, mpz_t out);void rsa_decrypt(rsa_secret_key *sec, mpz_t in, mpz_t out);void rsa_debug_print_sec(rsa_secret_key *sec);void rsa_debug_print_pub(rsa_public_key *pub);void rsa_init_sec(rsa_secret_key *sec);void rsa_clear_sec(rsa_secret_key *sec);void rsa_init_pub(rsa_public_key *pub);void rsa_clear_pub(rsa_public_key *pub);int rsa_write_file_sec(FILE *f, rsa_secret_key *sec);int rsa_read_file_sec(FILE *f, rsa_secret_key *sec);int rsa_generate_key(int bits, rsa_secret_key *sec);void rsa_secret_public(rsa_secret_key *sec, rsa_public_key *pub);int rsa_random_prime(mpz_t res, int bits);int jm_mpz_to_buf(mpz_t num, unsigned char *buf);int jm_buf_to_mpz(const unsigned char *buf, int max_len, mpz_t num);/* converts RSA public key structure to a char buffer * allocates memory for the buffer and returns the pointer to the buffer * or NULL on failure. buf_len is set to the length of the buffer in bytes * if the operation succeeds */unsigned char *rsa_public_key_buffer(rsa_public_key *pub, unsigned int *buf_len);/* converts char buffer to a RSA public key structure * buf - pointer to the char array * max_len - number of bytes that the routine is allowed to use (buffer size) * pub - pointer to a memory containing uninitialized rsa_public_key structure * returns number of bytes used or -1 on error */int rsa_buffer_public_key(const unsigned char *buf, unsigned int max_len, rsa_public_key *pub);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -