29 * Contributor(s):
30 * Netscape Communications Corporation
31 *
32 * Alternatively, the contents of this file may be used under the terms of
33 * either the GNU General Public License Version 2 or later (the "GPL"), or
34 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
35 * in which case the provisions of the GPL or the LGPL are applicable instead
36 * of those above. If you wish to allow use of your version of this file only
37 * under the terms of either the GPL or the LGPL, and not to allow others to
38 * use your version of this file under the terms of the MPL, indicate your
39 * decision by deleting the provisions above and replace them with the notice
40 * and other provisions required by the GPL or the LGPL. If you do not delete
41 * the provisions above, a recipient may use your version of this file under
42 * the terms of any one of the MPL, the GPL or the LGPL.
43 *
44 * ***** END LICENSE BLOCK ***** */
45 /*
46 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
47 * Use is subject to license terms.
48 *
49 * Sun elects to use this software under the MPL license.
50 */
51
52 #ifndef _MPI_PRIV_H
53 #define _MPI_PRIV_H
54
55 #pragma ident "%Z%%M% %I% %E% SMI"
56
57 /* $Id: mpi-priv.h,v 1.20 2005/11/22 07:16:43 relyea%netscape.com Exp $ */
58
59 #include "mpi.h"
60 #ifndef _KERNEL
61 #include <stdlib.h>
62 #include <string.h>
63 #include <ctype.h>
64 #endif /* _KERNEL */
65
66 #if MP_DEBUG
67 #include <stdio.h>
68
69 #define DIAG(T,V) {fprintf(stderr,T);mp_print(V,stderr);fputc('\n',stderr);}
70 #else
71 #define DIAG(T,V)
72 #endif
73
74 /* If we aren't using a wired-in logarithm table, we need to include
75 the math library to get the log() function
76 */
283
284 void MPI_ASM_DECL s_mpv_mul_d(const mp_digit *a, mp_size a_len,
285 mp_digit b, mp_digit *c);
286 void MPI_ASM_DECL s_mpv_mul_d_add(const mp_digit *a, mp_size a_len,
287 mp_digit b, mp_digit *c);
288
289 #endif
290
291 void MPI_ASM_DECL s_mpv_mul_d_add_prop(const mp_digit *a,
292 mp_size a_len, mp_digit b,
293 mp_digit *c);
294 void MPI_ASM_DECL s_mpv_sqr_add_prop(const mp_digit *a,
295 mp_size a_len,
296 mp_digit *sqrs);
297
298 mp_err MPI_ASM_DECL s_mpv_div_2dx1d(mp_digit Nhi, mp_digit Nlo,
299 mp_digit divisor, mp_digit *quot, mp_digit *rem);
300
301 /* c += a * b * (MP_RADIX ** offset); */
302 #define s_mp_mul_d_add_offset(a, b, c, off) \
303 (s_mpv_mul_d_add_prop(MP_DIGITS(a), MP_USED(a), b, MP_DIGITS(c) + off), MP_OKAY)
304
305 typedef struct {
306 mp_int N; /* modulus N */
307 mp_digit n0prime; /* n0' = - (n0 ** -1) mod MP_RADIX */
308 mp_size b; /* R == 2 ** b, also b = # significant bits in N */
309 } mp_mont_modulus;
310
311 mp_err s_mp_mul_mont(const mp_int *a, const mp_int *b, mp_int *c,
312 mp_mont_modulus *mmm);
313 mp_err s_mp_redc(mp_int *T, mp_mont_modulus *mmm);
314
315 /*
316 * s_mpi_getProcessorLineSize() returns the size in bytes of the cache line
317 * if a cache exists, or zero if there is no cache. If more than one
318 * cache line exists, it should return the smallest line size (which is
319 * usually the L1 cache).
320 *
321 * mp_modexp uses this information to make sure that private key information
322 * isn't being leaked through the cache.
323 *
|
29 * Contributor(s):
30 * Netscape Communications Corporation
31 *
32 * Alternatively, the contents of this file may be used under the terms of
33 * either the GNU General Public License Version 2 or later (the "GPL"), or
34 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
35 * in which case the provisions of the GPL or the LGPL are applicable instead
36 * of those above. If you wish to allow use of your version of this file only
37 * under the terms of either the GPL or the LGPL, and not to allow others to
38 * use your version of this file under the terms of the MPL, indicate your
39 * decision by deleting the provisions above and replace them with the notice
40 * and other provisions required by the GPL or the LGPL. If you do not delete
41 * the provisions above, a recipient may use your version of this file under
42 * the terms of any one of the MPL, the GPL or the LGPL.
43 *
44 * ***** END LICENSE BLOCK ***** */
45 /*
46 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
47 * Use is subject to license terms.
48 *
49 * Copyright 2017 RackTop Systems.
50 *
51 * Sun elects to use this software under the MPL license.
52 */
53
54 #ifndef _MPI_PRIV_H
55 #define _MPI_PRIV_H
56
57 /* $Id: mpi-priv.h,v 1.20 2005/11/22 07:16:43 relyea%netscape.com Exp $ */
58
59 #include "mpi.h"
60 #ifndef _KERNEL
61 #include <stdlib.h>
62 #include <string.h>
63 #include <ctype.h>
64 #endif /* _KERNEL */
65
66 #if MP_DEBUG
67 #include <stdio.h>
68
69 #define DIAG(T,V) {fprintf(stderr,T);mp_print(V,stderr);fputc('\n',stderr);}
70 #else
71 #define DIAG(T,V)
72 #endif
73
74 /* If we aren't using a wired-in logarithm table, we need to include
75 the math library to get the log() function
76 */
283
284 void MPI_ASM_DECL s_mpv_mul_d(const mp_digit *a, mp_size a_len,
285 mp_digit b, mp_digit *c);
286 void MPI_ASM_DECL s_mpv_mul_d_add(const mp_digit *a, mp_size a_len,
287 mp_digit b, mp_digit *c);
288
289 #endif
290
291 void MPI_ASM_DECL s_mpv_mul_d_add_prop(const mp_digit *a,
292 mp_size a_len, mp_digit b,
293 mp_digit *c);
294 void MPI_ASM_DECL s_mpv_sqr_add_prop(const mp_digit *a,
295 mp_size a_len,
296 mp_digit *sqrs);
297
298 mp_err MPI_ASM_DECL s_mpv_div_2dx1d(mp_digit Nhi, mp_digit Nlo,
299 mp_digit divisor, mp_digit *quot, mp_digit *rem);
300
301 /* c += a * b * (MP_RADIX ** offset); */
302 #define s_mp_mul_d_add_offset(a, b, c, off) \
303 s_mpv_mul_d_add_prop(MP_DIGITS(a), MP_USED(a), b, MP_DIGITS(c) + off)
304
305 typedef struct {
306 mp_int N; /* modulus N */
307 mp_digit n0prime; /* n0' = - (n0 ** -1) mod MP_RADIX */
308 mp_size b; /* R == 2 ** b, also b = # significant bits in N */
309 } mp_mont_modulus;
310
311 mp_err s_mp_mul_mont(const mp_int *a, const mp_int *b, mp_int *c,
312 mp_mont_modulus *mmm);
313 mp_err s_mp_redc(mp_int *T, mp_mont_modulus *mmm);
314
315 /*
316 * s_mpi_getProcessorLineSize() returns the size in bytes of the cache line
317 * if a cache exists, or zero if there is no cache. If more than one
318 * cache line exists, it should return the smallest line size (which is
319 * usually the L1 cache).
320 *
321 * mp_modexp uses this information to make sure that private key information
322 * isn't being leaked through the cache.
323 *
|