X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcmath%2Fsilcmp.h;h=5ff3d34772b70e15b409a0a4b0b400f2e9fc817e;hb=838fe0781769e5734459fdba84b1b1794574da7e;hp=aaff041274be97127ee878f6258d72e27daa54da;hpb=410642a14d4185abd75715cee3f5177cd55b1ceb;p=crypto.git diff --git a/lib/silcmath/silcmp.h b/lib/silcmath/silcmp.h index aaff0412..5ff3d347 100644 --- a/lib/silcmath/silcmp.h +++ b/lib/silcmath/silcmp.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2005 Pekka Riikonen + Copyright (C) 1997 - 2008 Pekka Riikonen 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 @@ -17,7 +17,7 @@ */ -/****h* silcmath/SILC MP Interface +/****h* silcmath/MP Integer Interface * * DESCRIPTION * @@ -43,7 +43,7 @@ #endif /* SILC_DIST_TFM */ #endif -/****d* silcmath/SilcMPAPI/SilcMPInt +/****d* silcmath/SilcMPInt * * NAME * @@ -60,22 +60,22 @@ typedef SILC_MP_INT SilcMPInt; /***/ -/****f* silcmath/SilcMPAPI/silc_mp_init +/****f* silcmath/silc_mp_init * * SYNOPSIS * - * void silc_mp_init(SilcMPInt mp); + * SilcBool silc_mp_init(SilcMPInt mp); * * DESCRIPTION * - * Initializes the SilcMPInt *that is the actual MP Integer. - * This must be called before any of the silc_mp_ routines can be - * used. The integer is uninitialized with the silc_mp_uninit function. + * Initializes the MP integer. This must be called before calling any + * other routine in SILC MP API. The silc_mp_uninit must be called + * to uninitialize the integer. Returns FALSE on error, TRUE otherwise. * ***/ -void silc_mp_init(SilcMPInt *mp); +SilcBool silc_mp_init(SilcMPInt *mp); -/****f* silcmath/SilcMPAPI/silc_mp_sinit +/****f* silcmath/silc_mp_sinit * * SYNOPSIS * @@ -83,23 +83,18 @@ void silc_mp_init(SilcMPInt *mp); * * DESCRIPTION * - * Initializes the SilcMPInt *that is the actual MP Integer. - * This must be called before any of the silc_mp_ routines can be - * used. The integer is uninitialized with the silc_mp_uninit function. - * This routine is equivalent to silc_mp_init but allocates the memory - * from `stack'. + * Initializes the MP integer. This must be called before calling any + * other routine in SILC MP API. The silc_mp_uninit must be called + * to uninitialize the integer. Returns FALSE on error, TRUE otherwise. * - * NOTES - * - * The `stack' is saved into the `mp' for the duration of the existence - * of `mp'. This means that `stack' must not become invalid while `mp' - * is used. It also means that any routine that may need memory allocation - * to for example enlarge `mp' will allocate the memory from `stack'. + * If `stack' is non-NULL all memory is allocated from `stack'. If it + * is NULL this is equivalent to silc_mp_init. The silc_mp_uninit must + * be called to uninitialize the integer even when `stack' is non-NULL. * ***/ SilcBool silc_mp_sinit(SilcStack stack, SilcMPInt *mp); -/****f* silcmath/SilcMPAPI/silc_mp_uninit +/****f* silcmath/silc_mp_uninit * * SYNOPSIS * @@ -112,7 +107,7 @@ SilcBool silc_mp_sinit(SilcStack stack, SilcMPInt *mp); ***/ void silc_mp_uninit(SilcMPInt *mp); -/****f* silcmath/SilcMPAPI/silc_mp_size +/****f* silcmath/silc_mp_size * * SYNOPSIS * @@ -125,7 +120,7 @@ void silc_mp_uninit(SilcMPInt *mp); ***/ size_t silc_mp_size(SilcMPInt *mp); -/****f* silcmath/SilcMPAPI/silc_mp_sizeinbase +/****f* silcmath/silc_mp_sizeinbase * * SYNOPSIS * @@ -147,25 +142,25 @@ size_t silc_mp_size(SilcMPInt *mp); ***/ size_t silc_mp_sizeinbase(SilcMPInt *mp, int base); -/****f* silcmath/SilcMPAPI/silc_mp_set +/****f* silcmath/silc_mp_set * * SYNOPSIS * - * void silc_mp_set(SilcMPInt *dst, SilcMPInt *src); + * SilcBool silc_mp_set(SilcMPInt *dst, SilcMPInt *src); * * DESCRIPTION * * Set `dst' integer from `src' integer. The `dst' must already be - * initialized. + * initialized. This in effect copies the integer from `src' to `dst'. * ***/ -void silc_mp_set(SilcMPInt *dst, SilcMPInt *src); +SilcBool silc_mp_set(SilcMPInt *dst, SilcMPInt *src); -/****f* silcmath/SilcMPAPI/silc_mp_set_ui +/****f* silcmath/silc_mp_set_ui * * SYNOPSIS * - * void silc_mp_set_ui(SilcMPInt *dst, SilcUInt32 ui); + * SilcBool silc_mp_set_ui(SilcMPInt *dst, SilcUInt32 ui); * * DESCRIPTION * @@ -173,13 +168,13 @@ void silc_mp_set(SilcMPInt *dst, SilcMPInt *src); * initialized. * ***/ -void silc_mp_set_ui(SilcMPInt *dst, SilcUInt32 ui); +SilcBool silc_mp_set_ui(SilcMPInt *dst, SilcUInt32 ui); -/****f* silcmath/SilcMPAPI/silc_mp_set_si +/****f* silcmath/silc_mp_set_si * * SYNOPSIS * - * void silc_mp_set_si(SilcMPInt *dst, SilcInt32 si); + * SilcBool silc_mp_set_si(SilcMPInt *dst, SilcInt32 si); * * DESCRIPTION * @@ -187,13 +182,13 @@ void silc_mp_set_ui(SilcMPInt *dst, SilcUInt32 ui); * already be initialized. * ***/ -void silc_mp_set_si(SilcMPInt *dst, SilcInt32 si); +SilcBool silc_mp_set_si(SilcMPInt *dst, SilcInt32 si); -/****f* silcmath/SilcMPAPI/silc_mp_set_str +/****f* silcmath/silc_mp_set_str * * SYNOPSIS * - * void silc_mp_set_str(SilcMPInt *dst, const char *str, int base); + * SilcBool silc_mp_set_str(SilcMPInt *dst, const char *str, int base); * * DESCRIPTION * @@ -206,9 +201,9 @@ void silc_mp_set_si(SilcMPInt *dst, SilcInt32 si); * binary. Use the silc_mp_bin2mp to decode binary into integer. * ***/ -void silc_mp_set_str(SilcMPInt *dst, const char *str, int base); +SilcBool silc_mp_set_str(SilcMPInt *dst, const char *str, int base); -/****f* silcmath/SilcMPAPI/silc_mp_get_ui +/****f* silcmath/silc_mp_get_ui * * SYNOPSIS * @@ -221,11 +216,11 @@ void silc_mp_set_str(SilcMPInt *dst, const char *str, int base); ***/ SilcUInt32 silc_mp_get_ui(SilcMPInt *mp); -/****f* silcmath/SilcMPAPI/silc_mp_get_str +/****f* silcmath/silc_mp_get_str * * SYNOPSIS * - * void silc_mp_get_str(char *str, SilcMPInt *mp, int base); + * char *silc_mp_get_str(char *str, SilcMPInt *mp, int base); * * DESCRIPTION * @@ -241,24 +236,24 @@ SilcUInt32 silc_mp_get_ui(SilcMPInt *mp); ***/ char *silc_mp_get_str(char *str, SilcMPInt *mp, int base); -/****f* silcmath/SilcMPAPI/silc_mp_add +/****f* silcmath/silc_mp_add * * SYNOPSIS * - * void silc_mp_add(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); + * SilcBool silc_mp_add(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * * DESCRIPTION * * Add two integers `mp1' and `mp2' and save the result to `dst'. * ***/ -void silc_mp_add(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); +SilcBool silc_mp_add(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); -/****f* silcmath/SilcMPAPI/silc_mp_add_ui +/****f* silcmath/silc_mp_add_ui * * SYNOPSIS * - * void silc_mp_add_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); + * SilcBool silc_mp_add_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); * * DESCRIPTION * @@ -266,26 +261,26 @@ void silc_mp_add(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * to `dst'. * ***/ -void silc_mp_add_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); +SilcBool silc_mp_add_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); -/****f* silcmath/SilcMPAPI/silc_mp_sub +/****f* silcmath/silc_mp_sub * * SYNOPSIS * - * void silc_mp_sub(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); + * SilcBool silc_mp_sub(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * * DESCRIPTION * * Subtract two integers `mp1' and `mp2' and save the result to `dst'. * ***/ -void silc_mp_sub(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); +SilcBool silc_mp_sub(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); -/****f* silcmath/SilcMPAPI/silc_mp_sub_ui +/****f* silcmath/silc_mp_sub_ui * * SYNOPSIS * - * void silc_mp_sub_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); + * SilcBool silc_mp_sub_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); * * DESCRIPTION * @@ -293,26 +288,26 @@ void silc_mp_sub(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * to `dst'. * ***/ -void silc_mp_sub_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); +SilcBool silc_mp_sub_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); -/****f* silcmath/SilcMPAPI/silc_mp_mul +/****f* silcmath/silc_mp_mul * * SYNOPSIS * - * void silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); + * SilcBool silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * * DESCRIPTION * * Multiply two integers `mp1' and `mp2' and save the result to `dst'. * ***/ -void silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); +SilcBool silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); -/****f* silcmath/SilcMPAPI/silc_mp_mul_ui +/****f* silcmath/silc_mp_mul_ui * * SYNOPSIS * - * void silc_mp_mul_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); + * SilcBool silc_mp_mul_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); * * DESCRIPTION * @@ -320,13 +315,13 @@ void silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * to `dst'. * ***/ -void silc_mp_mul_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); +SilcBool silc_mp_mul_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); -/****f* silcmath/SilcMPAPI/silc_mp_mul_2exp +/****f* silcmath/silc_mp_mul_2exp * * SYNOPSIS * - * void silc_mp_mul_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp); + * SilcBool silc_mp_mul_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp); * * DESCRIPTION * @@ -334,26 +329,26 @@ void silc_mp_mul_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); * `dst'. This is equivalent to dst = mp1 * (2 ^ exp). * ***/ -void silc_mp_mul_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp); +SilcBool silc_mp_mul_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp); -/****f* silcmath/SilcMPAPI/silc_mp_sqrt +/****f* silcmath/silc_mp_sqrt * * SYNOPSIS * - * void silc_mp_sqrt(SilcMPInt *dst, SilcMPInt *src); + * SilcBool silc_mp_sqrt(SilcMPInt *dst, SilcMPInt *src); * * DESCRIPTION * * Compute square root of floor(sqrt(src)) and save the result to `dst'. * ***/ -void silc_mp_sqrt(SilcMPInt *dst, SilcMPInt *src); +SilcBool silc_mp_sqrt(SilcMPInt *dst, SilcMPInt *src); -/****f* silcmath/SilcMPAPI/silc_mp_div +/****f* silcmath/silc_mp_div * * SYNOPSIS * - * void silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); + * SilcBool silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * * DESCRIPTION * @@ -361,13 +356,13 @@ void silc_mp_sqrt(SilcMPInt *dst, SilcMPInt *src); * is equivalent to dst = mp1 / mp2; * ***/ -void silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); +SilcBool silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); -/****f* silcmath/SilcMPAPI/silc_mp_div_ui +/****f* silcmath/silc_mp_div_ui * * SYNOPSIS * - * void silc_mp_div_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); + * SilcBool silc_mp_div_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); * * DESCRIPTION * @@ -375,14 +370,14 @@ void silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * `dst'. This is equivalent to dst = mp1 / ui; * ***/ -void silc_mp_div_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); +SilcBool silc_mp_div_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); -/****f* silcmath/SilcMPAPI/silc_mp_div_qr +/****f* silcmath/silc_mp_div_qr * * SYNOPSIS * - * void silc_mp_div_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, - * SilcMPInt *mp2); + * SilcBool silc_mp_div_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, + * SilcMPInt *mp2); * * DESCRIPTION * @@ -392,14 +387,14 @@ void silc_mp_div_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); * then the operation is omitted. * ***/ -void silc_mp_div_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, - SilcMPInt *mp2); +SilcBool silc_mp_div_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, + SilcMPInt *mp2); -/****f* silcmath/SilcMPAPI/silc_mp_div_2exp +/****f* silcmath/silc_mp_div_2exp * * SYNOPSIS * - * void silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); + * SilcBool silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * * DESCRIPTION * @@ -407,14 +402,14 @@ void silc_mp_div_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, * This is equivalent to dst = mp1 / (2 ^ exp). * ***/ -void silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp); +SilcBool silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp); -/****f* silcmath/SilcMPAPI/silc_mp_div_2exp_qr +/****f* silcmath/silc_mp_div_2exp_qr * * SYNOPSIS * - * void silc_mp_div_2exp_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, - * SilcUInt32 exp); + * SilcBool silc_mp_div_2exp_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, + * SilcUInt32 exp); * * DESCRIPTION * @@ -424,14 +419,14 @@ void silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp); * is omitted. * ***/ -void silc_mp_div_2exp_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, - SilcUInt32 exp); +SilcBool silc_mp_div_2exp_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, + SilcUInt32 exp); -/****f* silcmath/SilcMPAPI/silc_mp_mod +/****f* silcmath/silc_mp_mod * * SYNOPSIS * - * void silc_mp_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); + * SilcBool silc_mp_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * * DESCRIPTION * @@ -441,13 +436,13 @@ void silc_mp_div_2exp_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1, * returns the remainder as well. * ***/ -void silc_mp_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); +SilcBool silc_mp_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); -/****f* silcmath/SilcMPAPI/silc_mp_mod_ui +/****f* silcmath/silc_mp_mod_ui * * SYNOPSIS * - * void silc_mp_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); + * SilcBool silc_mp_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); * * DESCRIPTION * @@ -456,13 +451,13 @@ void silc_mp_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * to dst = mp1 mod ui. * ***/ -void silc_mp_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); +SilcBool silc_mp_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); -/****f* silcmath/SilcMPAPI/silc_mp_mod_2exp +/****f* silcmath/silc_mp_mod_2exp * * SYNOPSIS * - * void silc_mp_mod_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); + * SilcBool silc_mp_mod_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * * DESCRIPTION * @@ -472,13 +467,13 @@ void silc_mp_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); * function returns the remainder as well. * ***/ -void silc_mp_mod_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); +SilcBool silc_mp_mod_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); -/****f* silcmath/SilcMPAPI/silc_mp_pow +/****f* silcmath/silc_mp_pow_ui * * SYNOPSIS * - * void silc_mp_pow(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp); + * SilcBool silc_mp_pow_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp); * * DESCRIPTION * @@ -486,28 +481,14 @@ void silc_mp_mod_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui); * equivalent to dst = mp1 ^ exp. * ***/ -void silc_mp_pow(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp); +SilcBool silc_mp_pow_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp); -/****f* silcmath/SilcMPAPI/silc_mp_pow_ui +/****f* silcmath/silc_mp_pow_mod * * SYNOPSIS * - * void silc_mp_pow_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp); - * - * DESCRIPTION - * - * Compute `mp1' ** `exp' and save the result to `dst'. This is - * equivalent to dst = mp1 ^ exp. - * - ***/ -void silc_mp_pow_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp); - -/****f* silcmath/SilcMPAPI/silc_mp_pow_mod - * - * SYNOPSIS - * - * void silc_mp_pow_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp, - * SilcMPInt *mod); + * SilcBool silc_mp_pow_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp, + * SilcMPInt *mod); * * DESCRIPTION * @@ -515,15 +496,15 @@ void silc_mp_pow_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp); * This is equivalent to dst = (mp1 ^ exp) mod mod. * ***/ -void silc_mp_pow_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp, - SilcMPInt *mod); +SilcBool silc_mp_pow_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp, + SilcMPInt *mod); -/****f* silcmath/SilcMPAPI/silc_mp_pow_mod_ui +/****f* silcmath/silc_mp_pow_mod_ui * * SYNOPSIS * - * void silc_mp_pow_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp, - * SilcMPInt *mod); + * SilcBool silc_mp_pow_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, + * SilcUInt32 exp, SilcMPInt *mod); * * DESCRIPTION * @@ -531,14 +512,14 @@ void silc_mp_pow_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp, * This is equivalent to dst = (mp1 ^ exp) mod mod. * ***/ -void silc_mp_pow_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp, - SilcMPInt *mod); +SilcBool silc_mp_pow_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp, + SilcMPInt *mod); -/****f* silcmath/SilcMPAPI/silc_mp_modinv +/****f* silcmath/silc_mp_modinv * * SYNOPSIS * - * void silc_mp_modinv(SilcMPInt *inv, SilcMPInt *a, SilcMPInt *n); + * SilcBool silc_mp_modinv(SilcMPInt *inv, SilcMPInt *a, SilcMPInt *n); * * DESCRIPTION * @@ -560,13 +541,13 @@ void silc_mp_pow_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp, * not needed by the algorithm so it does not have to be included.) * ***/ -void silc_mp_modinv(SilcMPInt *inv, SilcMPInt *a, SilcMPInt *n); +SilcBool silc_mp_modinv(SilcMPInt *inv, SilcMPInt *a, SilcMPInt *n); -/****f* silcmath/SilcMPAPI/silc_mp_gcd +/****f* silcmath/silc_mp_gcd * * SYNOPSIS * - * void silc_mp_gcd(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); + * SilcBool silc_mp_gcd(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * * DESCRIPTION * @@ -574,25 +555,9 @@ void silc_mp_modinv(SilcMPInt *inv, SilcMPInt *a, SilcMPInt *n); * and save the result to `dst'. * ***/ -void silc_mp_gcd(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); - -/****f* silcmath/SilcMPAPI/silc_mp_gcdext - * - * SYNOPSIS - * - * void silc_mp_gcdext(SilcMPInt *g, SilcMPInt *s, SilcMPInt *t, - * SilcMPInt *mp1, SilcMPInt *mp2); - * - * DESCRIPTION - * - * Calculate the extended greatest common divisor `g', `s' and `t' such - * that g = mp1 * s + mp2 * + t. - * - ***/ -void silc_mp_gcdext(SilcMPInt *g, SilcMPInt *s, SilcMPInt *t, SilcMPInt *mp1, - SilcMPInt *mp2); +SilcBool silc_mp_gcd(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); -/****f* silcmath/SilcMPAPI/silc_mp_cmp +/****f* silcmath/silc_mp_cmp * * SYNOPSIS * @@ -606,7 +571,7 @@ void silc_mp_gcdext(SilcMPInt *g, SilcMPInt *s, SilcMPInt *t, SilcMPInt *mp1, ***/ int silc_mp_cmp(SilcMPInt *mp1, SilcMPInt *mp2); -/****f* silcmath/SilcMPAPI/silc_mp_cmp_si +/****f* silcmath/silc_mp_cmp_si * * SYNOPSIS * @@ -620,7 +585,7 @@ int silc_mp_cmp(SilcMPInt *mp1, SilcMPInt *mp2); ***/ int silc_mp_cmp_si(SilcMPInt *mp1, SilcInt32 si); -/****f* silcmath/SilcMPAPI/silc_mp_cmp_ui +/****f* silcmath/silc_mp_cmp_ui * * SYNOPSIS * @@ -635,7 +600,7 @@ int silc_mp_cmp_si(SilcMPInt *mp1, SilcInt32 si); ***/ int silc_mp_cmp_ui(SilcMPInt *mp1, SilcUInt32 ui); -/****f* silcmath/SilcMPAPI/silc_mp_mp2bin +/****f* silcmath/silc_mp_mp2bin * * SYNOPSIS * @@ -652,7 +617,7 @@ int silc_mp_cmp_ui(SilcMPInt *mp1, SilcUInt32 ui); unsigned char *silc_mp_mp2bin(SilcMPInt *val, SilcUInt32 len, SilcUInt32 *ret_len); -/****f* silcmath/SilcMPAPI/silc_mp_mp2bin_noalloc +/****f* silcmath/silc_mp_mp2bin_noalloc * * SYNOPSIS * @@ -668,7 +633,7 @@ unsigned char *silc_mp_mp2bin(SilcMPInt *val, SilcUInt32 len, void silc_mp_mp2bin_noalloc(SilcMPInt *val, unsigned char *dst, SilcUInt32 dst_len); -/****f* silcmath/SilcMPAPI/silc_mp_bin2mp +/****f* silcmath/silc_mp_bin2mp * * SYNOPSIS * @@ -683,69 +648,125 @@ void silc_mp_mp2bin_noalloc(SilcMPInt *val, unsigned char *dst, ***/ void silc_mp_bin2mp(unsigned char *data, SilcUInt32 len, SilcMPInt *ret); -/****f* silcmath/SilcMPAPI/silc_mp_abs +/****f* silcmath/silc_mp_abs * * SYNOPSIS * - * void silc_mp_abs(SilcMPInt *src, SilcMPInt *dst); + * SilcBool silc_mp_abs(SilcMPInt *src, SilcMPInt *dst); * * DESCRIPTION * * Assign the absolute value of `src' to `dst'. * ***/ -void silc_mp_abs(SilcMPInt *dst, SilcMPInt *src); +SilcBool silc_mp_abs(SilcMPInt *dst, SilcMPInt *src); -/****f* silcmath/SilcMPAPI/silc_mp_neg +/****f* silcmath/silc_mp_neg * * SYNOPSIS * - * void silc_mp_neg(SilcMPInt *dst, SilcMPInt *src); + * SilcBool silc_mp_neg(SilcMPInt *dst, SilcMPInt *src); * * DESCRIPTION * * Negate `src' and save the result to `dst'. * ***/ -void silc_mp_neg(SilcMPInt *dst, SilcMPInt *src); +SilcBool silc_mp_neg(SilcMPInt *dst, SilcMPInt *src); -/****f* silcmath/SilcMPAPI/silc_mp_and +/****f* silcmath/silc_mp_and * * SYNOPSIS * - * void silc_mp_and(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); + * SilcBool silc_mp_and(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * * DESCRIPTION * - * Logical and operator. The result is saved to `dst'. + * Bitwise AND operator. The result is saved to `dst'. * ***/ -void silc_mp_and(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); +SilcBool silc_mp_and(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); -/****f* silcmath/SilcMPAPI/silc_mp_or +/****f* silcmath/silc_mp_or * * SYNOPSIS * - * void silc_mp_or(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); + * SilcBool silc_mp_or(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * * DESCRIPTION * - * Logical inclusive OR operator. The result is saved to `dst'. + * Bitwise inclusive OR operator. The result is saved to `dst'. * ***/ -void silc_mp_or(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); +SilcBool silc_mp_or(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); -/****f* silcmath/SilcMPAPI/silc_mp_xor +/****f* silcmath/silc_mp_xor * * SYNOPSIS * - * void silc_mp_xor(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); + * SilcBool silc_mp_xor(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); * * DESCRIPTION * - * Logical exclusive OR operator. The result is saved to `dst'. + * Bitwise exclusive OR operator. The result is saved to `dst'. + * + ***/ +SilcBool silc_mp_xor(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); + +/* Utility functions */ + +/****f* silcmath/silc_mp_format + * + * SYNOPSIS + * + * int silc_mp_format(SilcStack stack, SilcBuffer buffer, + * void *value, void *context) + * + * DESCRIPTION + * + * MP integer encoding function to be used with silc_buffer_format and + * SILC_STR_FUNC formatter. The encoded data is of following format: + * + * SILC_STR_UINT32, integer_len, + * SILC_STR_DATA integer_data + * + * EXAMPLE + * + * silc_buffer_format(buf, + * SILC_STR_FUNC(silc_mp_format, mpint, NULL), + * SILC_STR_END); + * + ***/ +int silc_mp_format(SilcStack stack, SilcBuffer buffer, + void *value, void *context); + +/****f* silcmath/silc_mp_unformat + * + * SYNOPSIS + * + * int silc_mp_unformat(SilcStack stack, SilcBuffer buffer, + * void **value, void *context) + * + * DESCRIPTION + * + * MP integer decoding function to be used with silc_buffer_unformat and + * SILC_STR_FUNC unformatter. This function expects that the length of + * the integer is encoded as 32-bit integer and precedes the integer + * data. + * + * EXAMPLE + * + * SilcMPint mp_ptr; + * + * silc_mp_init(&mpint); + * mp_ptr = &mpint; + * + * silc_buffer_unformat(buf, + * SILC_STR_FUNC(silc_mp_unformat, &mp_ptr, NULL), + * SILC_STR_END); * ***/ -void silc_mp_xor(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2); +int silc_mp_unformat(SilcStack stack, SilcBuffer buffer, + void **value, void *context); #endif