1 // natVMSecureRandomPosix.cc - Native part of VMSecureRandom class for POSIX.
3 /* Copyright (C) 2009 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
13 #include <sys/types.h>
21 #include <java/lang/InternalError.h>
22 #include <gnu/java/security/jce/prng/VMSecureRandom.h>
25 gnu::java::security::jce::prng::VMSecureRandom::natGenerateSeed(jbyteArray byte_array
, jint offset
, jint length
)
28 jbyte
*bytes
= elements (byte_array
);
31 for (a
= 0; a
< offset
; ++a
)
33 fd
= open ("/dev/random", O_RDONLY
);
37 jstring oserr
= JvNewStringLatin1 (strerror (errno
));
38 throw new ::java::lang::InternalError
39 (JvNewStringLatin1 ("Error opening /dev/random: ")->concat(oserr
));
42 count
= read (fd
, bytes
, length
);
47 jstring oserr
= JvNewStringLatin1 (strerror (errno
));
48 throw new ::java::lang::InternalError
49 (JvNewStringLatin1 ("Error reading /dev/random: ")->concat(oserr
));