aboutsummaryrefslogtreecommitdiff
path: root/libjava/gnu/java/security/jce
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/gnu/java/security/jce')
-rw-r--r--libjava/gnu/java/security/jce/prng/SecureRandomAdapter.h7
-rw-r--r--libjava/gnu/java/security/jce/prng/VMSecureRandom.h43
-rw-r--r--libjava/gnu/java/security/jce/prng/VMSecureRandom.java78
-rw-r--r--libjava/gnu/java/security/jce/prng/natVMSecureRandomPosix.cc54
4 files changed, 181 insertions, 1 deletions
diff --git a/libjava/gnu/java/security/jce/prng/SecureRandomAdapter.h b/libjava/gnu/java/security/jce/prng/SecureRandomAdapter.h
index 71b29f7734d..7495038c735 100644
--- a/libjava/gnu/java/security/jce/prng/SecureRandomAdapter.h
+++ b/libjava/gnu/java/security/jce/prng/SecureRandomAdapter.h
@@ -39,12 +39,17 @@ class gnu::java::security::jce::prng::SecureRandomAdapter : public ::java::secur
public: // actually protected
SecureRandomAdapter(::java::lang::String *);
public:
+ static JArray< jbyte > * getSeed(jint);
virtual JArray< jbyte > * engineGenerateSeed(jint);
virtual void engineNextBytes(JArray< jbyte > *);
virtual void engineSetSeed(JArray< jbyte > *);
private:
- ::gnu::java::security::prng::MDGenerator * __attribute__((aligned(__alignof__( ::java::security::SecureRandomSpi)))) adaptee;
+ jboolean __attribute__((aligned(__alignof__( ::java::security::SecureRandomSpi)))) isSeeded;
+ ::gnu::java::security::prng::MDGenerator * adaptee;
::java::lang::String * mdName;
+ static ::java::util::logging::Logger * logger;
+ static ::java::lang::String * SECURERANDOM_SOURCE;
+ static ::java::lang::String * JAVA_SECURITY_EGD;
public:
static ::java::lang::Class class$;
};
diff --git a/libjava/gnu/java/security/jce/prng/VMSecureRandom.h b/libjava/gnu/java/security/jce/prng/VMSecureRandom.h
new file mode 100644
index 00000000000..b24c805141a
--- /dev/null
+++ b/libjava/gnu/java/security/jce/prng/VMSecureRandom.h
@@ -0,0 +1,43 @@
+
+// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*-
+
+#ifndef __gnu_java_security_jce_prng_VMSecureRandom__
+#define __gnu_java_security_jce_prng_VMSecureRandom__
+
+#pragma interface
+
+#include <java/lang/Object.h>
+#include <gcj/array.h>
+
+extern "Java"
+{
+ namespace gnu
+ {
+ namespace java
+ {
+ namespace security
+ {
+ namespace jce
+ {
+ namespace prng
+ {
+ class VMSecureRandom;
+ }
+ }
+ }
+ }
+ }
+}
+
+class gnu::java::security::jce::prng::VMSecureRandom : public ::java::lang::Object
+{
+
+public: // actually package-private
+ VMSecureRandom();
+ static jint generateSeed(JArray< jbyte > *, jint, jint);
+ static jint natGenerateSeed(JArray< jbyte > *, jint, jint);
+public:
+ static ::java::lang::Class class$;
+};
+
+#endif // __gnu_java_security_jce_prng_VMSecureRandom__
diff --git a/libjava/gnu/java/security/jce/prng/VMSecureRandom.java b/libjava/gnu/java/security/jce/prng/VMSecureRandom.java
new file mode 100644
index 00000000000..62ff8b7aa93
--- /dev/null
+++ b/libjava/gnu/java/security/jce/prng/VMSecureRandom.java
@@ -0,0 +1,78 @@
+/* VMSecureRandom.java -- random seed generator.
+ Copyright (C) 2006, 2009 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.security.jce.prng;
+
+/**
+ * VM-specific methods for generating real (or almost real) random
+ * seeds. VM implementors should write a version of this class that
+ * reads random bytes from some system source.
+ */
+final class VMSecureRandom
+{
+
+ /**
+ * <p>
+ * Generate a random seed. Implementations are free to generate
+ * fewer random bytes than are requested, and leave the remaining
+ * bytes of the destination buffer as zeros. Implementations SHOULD,
+ * however, make a best-effort attempt to satisfy the request.
+ * </p>
+ * <p>
+ * The GCJ implementation uses a native method to read bytes from
+ * a system random source (e.g. /dev/random).
+ * </p>
+ *
+ * @param buffer The destination buffer.
+ * @param offset The offset in the buffer to start putting bytes.
+ * @param length The number of random bytes to generate.
+ * @return the number of bytes generated.
+ */
+ static int generateSeed(byte[] buffer, int offset, int length)
+ {
+ if (length < 0)
+ throw new IllegalArgumentException("length must be nonnegative");
+ if (offset < 0 || offset + length > buffer.length)
+ throw new IndexOutOfBoundsException();
+
+ return natGenerateSeed(buffer, offset, length);
+ }
+
+ static native int natGenerateSeed(byte[] buffer, int offset, int length);
+
+} \ No newline at end of file
diff --git a/libjava/gnu/java/security/jce/prng/natVMSecureRandomPosix.cc b/libjava/gnu/java/security/jce/prng/natVMSecureRandomPosix.cc
new file mode 100644
index 00000000000..a44f3f4573b
--- /dev/null
+++ b/libjava/gnu/java/security/jce/prng/natVMSecureRandomPosix.cc
@@ -0,0 +1,54 @@
+// natVMSecureRandomPosix.cc - Native part of VMSecureRandom class for POSIX.
+
+/* Copyright (C) 2009 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <gcj/cni.h>
+#include <java/lang/InternalError.h>
+#include <gnu/java/security/jce/prng/VMSecureRandom.h>
+
+jint
+gnu::java::security::jce::prng::VMSecureRandom::natGenerateSeed(jbyteArray byte_array, jint offset, jint length)
+{
+ int a, fd;
+ jbyte *bytes = elements (byte_array);
+ ssize_t count;
+
+ for (a = 0; a < offset; ++a)
+ bytes++;
+ fd = open ("/dev/random", O_RDONLY);
+
+ if (fd == -1)
+ {
+ jstring oserr = JvNewStringLatin1 (strerror (errno));
+ throw new ::java::lang::InternalError
+ (JvNewStringLatin1 ("Error opening /dev/random: ")->concat(oserr));
+ }
+
+ count = read (fd, bytes, length);
+ close (fd);
+
+ if (count == -1)
+ {
+ jstring oserr = JvNewStringLatin1 (strerror (errno));
+ throw new ::java::lang::InternalError
+ (JvNewStringLatin1 ("Error reading /dev/random: ")->concat(oserr));
+ }
+
+ return count;
+}
+