qfile.c revision 1.1 1 1.1 elad /* $NetBSD: qfile.c,v 1.1 2006/01/24 18:59:23 elad Exp $ */
2 1.1 elad
3 1.1 elad /*-
4 1.1 elad * Copyright 1994 Phil Karn <karn (at) qualcomm.com>
5 1.1 elad * Copyright 1996-1998, 2003 William Allen Simpson <wsimpson (at) greendragon.com>
6 1.1 elad * All rights reserved.
7 1.1 elad *
8 1.1 elad * Redistribution and use in source and binary forms, with or without
9 1.1 elad * modification, are permitted provided that the following conditions
10 1.1 elad * are met:
11 1.1 elad * 1. Redistributions of source code must retain the above copyright
12 1.1 elad * notice, this list of conditions and the following disclaimer.
13 1.1 elad * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 elad * notice, this list of conditions and the following disclaimer in the
15 1.1 elad * documentation and/or other materials provided with the distribution.
16 1.1 elad *
17 1.1 elad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 elad * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1 elad * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 elad * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1 elad * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1 elad * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1 elad * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1 elad * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1 elad * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 1.1 elad * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 elad */
28 1.1 elad
29 1.1 elad /*
30 1.1 elad * File I/O for qsafe and qsieve.
31 1.1 elad *
32 1.1 elad * 1996 May William Allen Simpson extracted from earlier code by Phil Karn,
33 1.1 elad * April 1994. save large primes list for later processing. 1998 May
34 1.1 elad * William Allen Simpson parameterized. 2003 Jun William Allen Simpson
35 1.1 elad * move common file i/o to own file for better documentation.
36 1.1 elad */
37 1.1 elad
38 1.1 elad #include <stdio.h>
39 1.1 elad #include <stdlib.h>
40 1.1 elad #include <time.h>
41 1.1 elad #include <openssl/bn.h>
42 1.1 elad #include "qfile.h"
43 1.1 elad
44 1.1 elad /*
45 1.1 elad * print moduli out in consistent form,
46 1.1 elad * normalizing error returns to printf-like expectations.
47 1.1 elad */
48 1.1 elad int
49 1.1 elad qfileout(FILE * ofile, uint32_t otype, uint32_t otests, uint32_t otries,
50 1.1 elad uint32_t osize, uint32_t ogenerator, BIGNUM * omodulus)
51 1.1 elad {
52 1.1 elad struct tm *gtm;
53 1.1 elad time_t time_now;
54 1.1 elad
55 1.1 elad time(&time_now);
56 1.1 elad gtm = gmtime(&time_now);
57 1.1 elad
58 1.1 elad if (0 > fprintf(ofile,
59 1.1 elad "%04d%02d%02d%02d%02d%02d %u %u %u %u %x ",
60 1.1 elad gtm->tm_year + 1900,
61 1.1 elad gtm->tm_mon + 1,
62 1.1 elad gtm->tm_mday,
63 1.1 elad gtm->tm_hour,
64 1.1 elad gtm->tm_min,
65 1.1 elad gtm->tm_sec,
66 1.1 elad otype,
67 1.1 elad otests,
68 1.1 elad otries,
69 1.1 elad osize,
70 1.1 elad ogenerator)) {
71 1.1 elad
72 1.1 elad return (-1);
73 1.1 elad }
74 1.1 elad
75 1.1 elad if (1 > BN_print_fp(ofile, omodulus)) {
76 1.1 elad return (-1);
77 1.1 elad }
78 1.1 elad
79 1.1 elad return (fprintf(ofile, "\n"));
80 1.1 elad }
81