2 * Copyright (C) 2007-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos, Simon Josefsson
6 * This file is part of GnuTLS.
8 * GnuTLS is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * GnuTLS is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with GnuTLS; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "../lib/gnutls_int.h"
31 #include "../lib/gnutls_mpi.h"
32 #include "../lib/gnutls_errors.h"
33 #include "../lib/debug.h"
36 tls_log_func (int level
, const char *str
)
38 fprintf (stderr
, "|<%d>| %s", level
, str
);
41 #define RND_BITS 510 /* not multiple of 8 */
46 bigint_t n1
, n2
, n3
, n4
;
48 gnutls_global_init ();
50 gnutls_global_set_log_function (tls_log_func
);
52 gnutls_global_set_log_level (99);
54 n1
= _gnutls_mpi_new (1000);
56 fail ("mpi_new failed\n");
58 n2
= _gnutls_mpi_set_ui (NULL
, 2);
60 fail ("mpi_set_ui failed\n");
62 n3
= _gnutls_mpi_set_ui (NULL
, 5);
64 fail ("mpi_set_ui failed\n");
66 _gnutls_mpi_randomize (n1
, RND_BITS
, GNUTLS_RND_NONCE
);
68 _gnutls_mpi_log ("rand:", n1
);
70 rc
= _gnutls_mpi_get_nbits (n1
);
72 fail ("mpi_get_nbits failed... returned %d\n", rc
);
74 n4
= _gnutls_mpi_addm (NULL
, n1
, n3
, n2
);
76 fail ("mpi_set_ui failed\n");
78 if (_gnutls_mpi_cmp_ui (n4
, 0) != 0 && _gnutls_mpi_cmp_ui (n4
, 1) != 0)
79 fail ("mpi_cmp_ui failed\n");
81 _gnutls_mpi_release (&n1
);
82 _gnutls_mpi_release (&n2
);
83 _gnutls_mpi_release (&n3
);
84 _gnutls_mpi_release (&n4
);
86 gnutls_global_deinit ();
88 if (debug
) success ("mpi ops ok\n");