108 try {
109 egdUrl = new URL(egdSource);
110 if (!egdUrl.getProtocol().equalsIgnoreCase("file")) {
111 return null;
112 }
113 } catch (MalformedURLException e) {
114 return null;
115 }
116 } else {
117 egdUrl = null;
118 }
119
120 return egdUrl;
121 }
122
123 /**
124 * Create a RandomIO object for all I/O of this Variant type.
125 */
126 private static RandomIO initIO(final Variant v) {
127 return AccessController.doPrivileged(
128 new PrivilegedAction<RandomIO>() {
129 @Override
130 public RandomIO run() {
131
132 File seedFile;
133 File nextFile;
134
135 switch(v) {
136 case MIXED:
137 URL egdUrl;
138 File egdFile = null;
139
140 if ((egdUrl = getEgdUrl()) != null) {
141 try {
142 egdFile = SunEntries.getDeviceFile(egdUrl);
143 } catch (IOException e) {
144 // Swallow, seedFile is still null
145 }
146 }
147
148 // Try egd first.
423 private byte[] implGenerateSeed(int numBytes) {
424 synchronized (LOCK_GET_SEED) {
425 try {
426 byte[] b = new byte[numBytes];
427 readFully(seedIn, b);
428 return b;
429 } catch (IOException e) {
430 throw new ProviderException("generateSeed() failed", e);
431 }
432 }
433 }
434
435 // supply random bytes to the OS
436 // write to "seed" if possible
437 // always add the seed to our mixing random
438 private void implSetSeed(byte[] seed) {
439 synchronized (LOCK_SET_SEED) {
440 if (seedOutInitialized == false) {
441 seedOutInitialized = true;
442 seedOut = AccessController.doPrivileged(
443 new PrivilegedAction<OutputStream>() {
444 @Override
445 public OutputStream run() {
446 try {
447 return new FileOutputStream(seedFile, true);
448 } catch (Exception e) {
449 return null;
450 }
451 }
452 });
453 }
454 if (seedOut != null) {
455 try {
456 seedOut.write(seed);
457 } catch (IOException e) {
458 throw new ProviderException("setSeed() failed", e);
459 }
460 }
461 getMixRandom().engineSetSeed(seed);
462 }
463 }
|
108 try {
109 egdUrl = new URL(egdSource);
110 if (!egdUrl.getProtocol().equalsIgnoreCase("file")) {
111 return null;
112 }
113 } catch (MalformedURLException e) {
114 return null;
115 }
116 } else {
117 egdUrl = null;
118 }
119
120 return egdUrl;
121 }
122
123 /**
124 * Create a RandomIO object for all I/O of this Variant type.
125 */
126 private static RandomIO initIO(final Variant v) {
127 return AccessController.doPrivileged(
128 new PrivilegedAction<>() {
129 @Override
130 public RandomIO run() {
131
132 File seedFile;
133 File nextFile;
134
135 switch(v) {
136 case MIXED:
137 URL egdUrl;
138 File egdFile = null;
139
140 if ((egdUrl = getEgdUrl()) != null) {
141 try {
142 egdFile = SunEntries.getDeviceFile(egdUrl);
143 } catch (IOException e) {
144 // Swallow, seedFile is still null
145 }
146 }
147
148 // Try egd first.
423 private byte[] implGenerateSeed(int numBytes) {
424 synchronized (LOCK_GET_SEED) {
425 try {
426 byte[] b = new byte[numBytes];
427 readFully(seedIn, b);
428 return b;
429 } catch (IOException e) {
430 throw new ProviderException("generateSeed() failed", e);
431 }
432 }
433 }
434
435 // supply random bytes to the OS
436 // write to "seed" if possible
437 // always add the seed to our mixing random
438 private void implSetSeed(byte[] seed) {
439 synchronized (LOCK_SET_SEED) {
440 if (seedOutInitialized == false) {
441 seedOutInitialized = true;
442 seedOut = AccessController.doPrivileged(
443 new PrivilegedAction<>() {
444 @Override
445 public OutputStream run() {
446 try {
447 return new FileOutputStream(seedFile, true);
448 } catch (Exception e) {
449 return null;
450 }
451 }
452 });
453 }
454 if (seedOut != null) {
455 try {
456 seedOut.write(seed);
457 } catch (IOException e) {
458 throw new ProviderException("setSeed() failed", e);
459 }
460 }
461 getMixRandom().engineSetSeed(seed);
462 }
463 }
|