~ubuntu-branches/ubuntu/precise/gnupg2/precise-proposed

« back to all changes in this revision

Viewing changes to cipher/rndriscos.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Urlichs
  • Date: 2006-01-24 04:31:42 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060124043142-pbg192or6qxv3yk2
Tags: 1.9.20-1
* New Upstream version. Closes:#306890,#344530
  * Closes:#320490: gpg-protect-tool fails to decrypt PKCS-12 files 
* Depend on libopensc2-dev, not -1-. Closes:#348106

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* rndriscos.c  -  raw random number for RISC OS
 
2
 *      Copyright (C) 2001 Free Software Foundation, Inc.
 
3
 *
 
4
 * This file is part of GnuPG.
 
5
 *
 
6
 * GnuPG is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * GnuPG is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
19
 */
 
20
 
 
21
#include <config.h>
 
22
 
 
23
#ifdef USE_RNDRISCOS
 
24
 
 
25
#include <string.h>
 
26
#include <kernel.h>
 
27
#include <swis.h>
 
28
#include "util.h"
 
29
 
 
30
static int init_device(void);
 
31
 
 
32
#define CryptRandom_Byte 0x51980
 
33
 
 
34
static const char * const path[] = {
 
35
    "GnuPG:CryptRandom",
 
36
    "GnuPG:CryptRand",
 
37
    "System:Modules.CryptRandom"
 
38
    "System:Modules.CryptRand",
 
39
    NULL
 
40
};
 
41
 
 
42
/****************
 
43
 * Used to load the CryptRandom module if it isn't already loaded
 
44
 */
 
45
static int
 
46
init_device(void)
 
47
{
 
48
    int i;
 
49
 
 
50
    /* Is CryptRandom already loaded? */
 
51
    if (!_swix(OS_Module, _INR(0,1), 18, "CryptRandom"))
 
52
        return 1;
 
53
 
 
54
    /* Check all the places where the module could be located */
 
55
    for (i=0; path[i]; ++i)
 
56
        if (!_swix(OS_Module, _INR(0,1), 1, path[i]))
 
57
            return 1;
 
58
 
 
59
    /* Can't find CryptRandom in the default locations */
 
60
    g10_log_fatal("Can't load module CryptRandom.\n");
 
61
 
 
62
    return 0; /* never reached, but don't throw a warning */
 
63
}
 
64
 
 
65
 
 
66
/****************
 
67
 * Get the random bytes from module
 
68
 */
 
69
int
 
70
rndriscos_gather_random(void (*add)(const void*, size_t, int), int requester,
 
71
                        size_t length, int level)
 
72
{
 
73
    static int initialized = 0;
 
74
    int n;
 
75
    byte buffer[768];
 
76
 
 
77
    if (!initialized)
 
78
        initialized = init_device();
 
79
 
 
80
    while (length) {
 
81
        int nbytes = length < sizeof(buffer) ? length : sizeof(buffer);
 
82
 
 
83
        for (n = 0; n < nbytes; ++n)
 
84
            if (_swix(CryptRandom_Byte, _OUT(0), &buffer[n]))
 
85
                g10_log_fatal("CryptRandom module isn't working as expected!\n");
 
86
 
 
87
        (*add)(buffer, n, requester);
 
88
        length -= n;
 
89
    }
 
90
    memset(buffer, 0, sizeof(buffer));
 
91
 
 
92
    return 0; /* success */
 
93
}
 
94
 
 
95
#endif /*USE_RNDRISCOS */