X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fsrc%2Fpdkim%2Fbignum.h;h=581f7f21c605b8ab0bf241a28be186919d11d707;hb=3a2ac12bcabf06f73ef372dfa23e6edead237aa7;hp=5b355f2fcec42c4336e54e564a39c4e97f8278d2;hpb=1ba28e2b955b005ce4825fec792df17f75a8de1e;p=exim.git diff --git a/src/src/pdkim/bignum.h b/src/src/pdkim/bignum.h index 5b355f2fc..581f7f21c 100644 --- a/src/src/pdkim/bignum.h +++ b/src/src/pdkim/bignum.h @@ -1,10 +1,12 @@ /** * \file bignum.h * - * Copyright (C) 2006-2009, Paul Bakker - * All rights reserved. + * Copyright (C) 2006-2010, Brainspark B.V. + * + * This file is part of PolarSSL (http://www.polarssl.org) + * Lead Maintainer: Paul Bakker * - * Joined copyright on original XySSL code with: Christophe Devine + * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,8 +23,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -/* $Cambridge: exim/src/src/pdkim/bignum.h,v 1.3 2009/12/07 13:05:07 tom Exp $ */ - #ifndef POLARSSL_BIGNUM_H #define POLARSSL_BIGNUM_H @@ -111,7 +111,7 @@ int mpi_grow( mpi *X, int nblimbs ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_copy( mpi *X, mpi *Y ); +int mpi_copy( mpi *X, const mpi *Y ); /** * \brief Swap the contents of X and Y @@ -137,21 +137,21 @@ int mpi_lset( mpi *X, int z ); * * \param X MPI to use */ -int mpi_lsb( mpi *X ); +int mpi_lsb( const mpi *X ); /** * \brief Return the number of most significant bits * * \param X MPI to use */ -int mpi_msb( mpi *X ); +int mpi_msb( const mpi *X ); /** * \brief Return the total size in bytes * * \param X MPI to use */ -int mpi_size( mpi *X ); +int mpi_size( const mpi *X ); /** * \brief Import from an ASCII string @@ -162,7 +162,7 @@ int mpi_size( mpi *X ); * * \return 0 if successful, or an POLARSSL_ERR_MPI_XXX error code */ -int mpi_read_string( mpi *X, int radix, char *s ); +int mpi_read_string( mpi *X, int radix, const char *s ); /** * \brief Export into an ASCII string @@ -172,12 +172,14 @@ int mpi_read_string( mpi *X, int radix, char *s ); * \param s String buffer * \param slen String buffer size * - * \return 0 if successful, or an POLARSSL_ERR_MPI_XXX error code + * \return 0 if successful, or an POLARSSL_ERR_MPI_XXX error code. + * *slen is always updated to reflect the amount + * of data that has (or would have) been written. * * \note Call this function with *slen = 0 to obtain the * minimum required buffer size in *slen. */ -int mpi_write_string( mpi *X, int radix, char *s, int *slen ); +int mpi_write_string( const mpi *X, int radix, char *s, int *slen ); /** * \brief Read X from an opened file @@ -202,7 +204,7 @@ int mpi_read_file( mpi *X, int radix, FILE *fin ); * * \note Set fout == NULL to print X on the console. */ -int mpi_write_file( const char *p, mpi *X, int radix, FILE *fout ); +int mpi_write_file( const char *p, const mpi *X, int radix, FILE *fout ); /** * \brief Import X from unsigned binary data, big endian @@ -214,7 +216,7 @@ int mpi_write_file( const char *p, mpi *X, int radix, FILE *fout ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_read_binary( mpi *X, unsigned char *buf, int buflen ); +int mpi_read_binary( mpi *X, const unsigned char *buf, int buflen ); /** * \brief Export X into unsigned binary data, big endian @@ -226,7 +228,7 @@ int mpi_read_binary( mpi *X, unsigned char *buf, int buflen ); * \return 0 if successful, * POLARSSL_ERR_MPI_BUFFER_TOO_SMALL if buf isn't large enough */ -int mpi_write_binary( mpi *X, unsigned char *buf, int buflen ); +int mpi_write_binary( const mpi *X, unsigned char *buf, int buflen ); /** * \brief Left-shift: X <<= count @@ -260,7 +262,7 @@ int mpi_shift_r( mpi *X, int count ); * -1 if |X| is lesser than |Y| or * 0 if |X| is equal to |Y| */ -int mpi_cmp_abs( mpi *X, mpi *Y ); +int mpi_cmp_abs( const mpi *X, const mpi *Y ); /** * \brief Compare signed values @@ -272,7 +274,7 @@ int mpi_cmp_abs( mpi *X, mpi *Y ); * -1 if X is lesser than Y or * 0 if X is equal to Y */ -int mpi_cmp_mpi( mpi *X, mpi *Y ); +int mpi_cmp_mpi( const mpi *X, const mpi *Y ); /** * \brief Compare signed values @@ -284,7 +286,7 @@ int mpi_cmp_mpi( mpi *X, mpi *Y ); * -1 if X is lesser than z or * 0 if X is equal to z */ -int mpi_cmp_int( mpi *X, int z ); +int mpi_cmp_int( const mpi *X, int z ); /** * \brief Unsigned addition: X = |A| + |B| @@ -296,7 +298,7 @@ int mpi_cmp_int( mpi *X, int z ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_add_abs( mpi *X, mpi *A, mpi *B ); +int mpi_add_abs( mpi *X, const mpi *A, const mpi *B ); /** * \brief Unsigned substraction: X = |A| - |B| @@ -308,7 +310,7 @@ int mpi_add_abs( mpi *X, mpi *A, mpi *B ); * \return 0 if successful, * POLARSSL_ERR_MPI_NEGATIVE_VALUE if B is greater than A */ -int mpi_sub_abs( mpi *X, mpi *A, mpi *B ); +int mpi_sub_abs( mpi *X, const mpi *A, const mpi *B ); /** * \brief Signed addition: X = A + B @@ -320,7 +322,7 @@ int mpi_sub_abs( mpi *X, mpi *A, mpi *B ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_add_mpi( mpi *X, mpi *A, mpi *B ); +int mpi_add_mpi( mpi *X, const mpi *A, const mpi *B ); /** * \brief Signed substraction: X = A - B @@ -332,7 +334,7 @@ int mpi_add_mpi( mpi *X, mpi *A, mpi *B ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_sub_mpi( mpi *X, mpi *A, mpi *B ); +int mpi_sub_mpi( mpi *X, const mpi *A, const mpi *B ); /** * \brief Signed addition: X = A + b @@ -344,7 +346,7 @@ int mpi_sub_mpi( mpi *X, mpi *A, mpi *B ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_add_int( mpi *X, mpi *A, int b ); +int mpi_add_int( mpi *X, const mpi *A, int b ); /** * \brief Signed substraction: X = A - b @@ -356,7 +358,7 @@ int mpi_add_int( mpi *X, mpi *A, int b ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_sub_int( mpi *X, mpi *A, int b ); +int mpi_sub_int( mpi *X, const mpi *A, int b ); /** * \brief Baseline multiplication: X = A * B @@ -368,7 +370,7 @@ int mpi_sub_int( mpi *X, mpi *A, int b ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_mul_mpi( mpi *X, mpi *A, mpi *B ); +int mpi_mul_mpi( mpi *X, const mpi *A, const mpi *B ); /** * \brief Baseline multiplication: X = A * b @@ -382,7 +384,7 @@ int mpi_mul_mpi( mpi *X, mpi *A, mpi *B ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_mul_int( mpi *X, mpi *A, t_int b ); +int mpi_mul_int( mpi *X, const mpi *A, t_int b ); /** * \brief Division by mpi: A = Q * B + R @@ -398,7 +400,7 @@ int mpi_mul_int( mpi *X, mpi *A, t_int b ); * * \note Either Q or R can be NULL. */ -int mpi_div_mpi( mpi *Q, mpi *R, mpi *A, mpi *B ); +int mpi_div_mpi( mpi *Q, mpi *R, const mpi *A, const mpi *B ); /** * \brief Division by int: A = Q * b + R @@ -414,7 +416,7 @@ int mpi_div_mpi( mpi *Q, mpi *R, mpi *A, mpi *B ); * * \note Either Q or R can be NULL. */ -int mpi_div_int( mpi *Q, mpi *R, mpi *A, int b ); +int mpi_div_int( mpi *Q, mpi *R, const mpi *A, int b ); /** * \brief Modulo: R = A mod B @@ -428,12 +430,12 @@ int mpi_div_int( mpi *Q, mpi *R, mpi *A, int b ); * POLARSSL_ERR_MPI_DIVISION_BY_ZERO if B == 0, * POLARSSL_ERR_MPI_NEGATIVE_VALUE if B < 0 */ -int mpi_mod_mpi( mpi *R, mpi *A, mpi *B ); +int mpi_mod_mpi( mpi *R, const mpi *A, const mpi *B ); /** * \brief Modulo: r = A mod b * - * \param a Destination t_int + * \param r Destination t_int * \param A Left-hand MPI * \param b Integer to divide by * @@ -442,7 +444,7 @@ int mpi_mod_mpi( mpi *R, mpi *A, mpi *B ); * POLARSSL_ERR_MPI_DIVISION_BY_ZERO if b == 0, * POLARSSL_ERR_MPI_NEGATIVE_VALUE if b < 0 */ -int mpi_mod_int( t_int *r, mpi *A, int b ); +int mpi_mod_int( t_int *r, const mpi *A, int b ); /** * \brief Sliding-window exponentiation: X = A^E mod N @@ -461,7 +463,7 @@ int mpi_mod_int( t_int *r, mpi *A, int b ); * multiple calls, which speeds up things a bit. It can * be set to NULL if the extra performance is unneeded. */ -int mpi_exp_mod( mpi *X, mpi *A, mpi *E, mpi *N, mpi *_RR ); +int mpi_exp_mod( mpi *X, const mpi *A, const mpi *E, const mpi *N, mpi *_RR ); /** * \brief Greatest common divisor: G = gcd(A, B) @@ -473,7 +475,7 @@ int mpi_exp_mod( mpi *X, mpi *A, mpi *E, mpi *N, mpi *_RR ); * \return 0 if successful, * 1 if memory allocation failed */ -int mpi_gcd( mpi *G, mpi *A, mpi *B ); +int mpi_gcd( mpi *G, const mpi *A, const mpi *B ); /** * \brief Modular inverse: X = A^-1 mod N @@ -487,7 +489,7 @@ int mpi_gcd( mpi *G, mpi *A, mpi *B ); * POLARSSL_ERR_MPI_BAD_INPUT_DATA if N is negative or nil POLARSSL_ERR_MPI_NOT_ACCEPTABLE if A has no inverse mod N */ -int mpi_inv_mod( mpi *X, mpi *A, mpi *N ); +int mpi_inv_mod( mpi *X, const mpi *A, const mpi *N ); /** * \brief Miller-Rabin primality test