OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [gnu/] [java/] [security/] [jce/] [prng/] [natVMSecureRandomPosix.cc] - Blame information for rev 756

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 756 jeremybenn
// natVMSecureRandomPosix.cc - Native part of VMSecureRandom class for POSIX.
2
 
3
/* Copyright (C) 2009 Free Software Foundation
4
 
5
   This file is part of libgcj.
6
 
7
This software is copyrighted work licensed under the terms of the
8
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9
details.  */
10
 
11
#include <config.h>
12
 
13
#include <sys/types.h>
14
#include <sys/stat.h>
15
#include <fcntl.h>
16
#include <unistd.h>
17
#include <string.h>
18
#include <errno.h>
19
 
20
#include <gcj/cni.h>
21
#include <java/lang/InternalError.h>
22
#include <gnu/java/security/jce/prng/VMSecureRandom.h>
23
 
24
jint
25
gnu::java::security::jce::prng::VMSecureRandom::natGenerateSeed(jbyteArray byte_array, jint offset, jint length)
26
{
27
  int a, fd;
28
  jbyte *bytes = elements (byte_array);
29
  ssize_t count;
30
 
31
  for (a = 0; a < offset; ++a)
32
    bytes++;
33
  fd = open ("/dev/random", O_RDONLY);
34
 
35
  if (fd == -1)
36
    {
37
      jstring oserr = JvNewStringLatin1 (strerror (errno));
38
      throw new ::java::lang::InternalError
39
        (JvNewStringLatin1 ("Error opening /dev/random: ")->concat(oserr));
40
    }
41
 
42
  count = read (fd, bytes, length);
43
  close (fd);
44
 
45
  if (count == -1)
46
    {
47
      jstring oserr = JvNewStringLatin1 (strerror (errno));
48
      throw new ::java::lang::InternalError
49
        (JvNewStringLatin1 ("Error reading /dev/random: ")->concat(oserr));
50
    }
51
 
52
  return count;
53
}
54
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.