@@ -0,0 +1,3083 @@
+/*%0A * Copyright 2013 Google Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.bitcoinj.crypto;%0A%0Aimport java.io.DataInputStream;%0Aimport java.io.File;%0Aimport java.io.FileInputStream;%0Aimport java.io.FileNotFoundException;%0Aimport java.io.IOException;%0Aimport java.security.Provider;%0Aimport java.security.SecureRandomSpi;%0Aimport java.security.Security;%0A%0A/**%0A * A SecureRandom implementation that is able to override the standard JVM provided implementation, and which simply%0A * serves random numbers by reading /dev/urandom. That is, it delegates to the kernel on UNIX systems and is unusable on%0A * other platforms. Attempts to manually set the seed are ignored. There is no difference between seed bytes and%0A * non-seed bytes, they are all from the same source.%0A */%0Apublic class LinuxSecureRandom extends SecureRandomSpi %7B%0A    private static final FileInputStream urandom;%0A%0A    private static class LinuxSecureRandomProvider extends Provider %7B%0A        public LinuxSecureRandomProvider() %7B%0A            super(%22LinuxSecureRandom%22, 1.0, %22A Linux specific random number provider that uses /dev/urandom%22);%0A            put(%22SecureRandom.LinuxSecureRandom%22, LinuxSecureRandom.class.getName());%0A        %7D%0A    %7D%0A%0A    static %7B%0A        try %7B%0A            File file = new File(%22/dev/urandom%22);%0A            if (file.exists()) %7B%0A                // This stream is deliberately leaked.%0A                urandom = new FileInputStream(file);%0A                // Now override the default SecureRandom implementation with this one.%0A                Security.insertProviderAt(new LinuxSecureRandomProvider(), 1);%0A            %7D else %7B%0A                urandom = null;%0A            %7D%0A        %7D catch (FileNotFoundException e) %7B%0A            // Should never happen.%0A            throw new RuntimeException(e);%0A        %7D%0A    %7D%0A%0A    private final DataInputStream dis;%0A%0A    public LinuxSecureRandom() %7B%0A        // DataInputStream is not thread safe, so each random object has its own.%0A        dis = new DataInputStream(urandom);%0A    %7D%0A%0A    @Override%0A    protected void engineSetSeed(byte%5B%5D bytes) %7B%0A        // Ignore.%0A    %7D%0A%0A    @Override%0A    protected void engineNextBytes(byte%5B%5D bytes) %7B%0A        try %7B%0A            dis.readFully(bytes); // This will block until all the bytes can be read.%0A        %7D catch (IOException e) %7B%0A            throw new RuntimeException(e); // Fatal error. Do not attempt to recover from this.%0A        %7D%0A    %7D%0A%0A    @Override%0A    protected byte%5B%5D engineGenerateSeed(int i) %7B%0A        byte%5B%5D bits = new byte%5Bi%5D;%0A        engineNextBytes(bits);%0A        return bits;%0A    %7D%0A%7D%0A

Move LinuxSecureRandom from Bitcoin Wallet to bitcoinj. This class is in use since August 2013 without any signs of RNG issues.