propagate from branch 'i2p.i2p' (head b82e829752729679ee6b9ece7ce8c7279c70aedf)

to branch 'i2p.i2p.zzz.test2' (head 8e441b5ba1384e499901127e10ab79b96f0f0cb5)
This commit is contained in:
zzz
2014-10-14 16:47:50 +00:00
117 changed files with 12684 additions and 11131 deletions

View File

@@ -2,21 +2,24 @@ package freenet.support.CPUInformation;
/**
* Moved out of CPUID.java
*
* Ref: http://en.wikipedia.org/wiki/List_of_AMD_CPU_microarchitectures
*
* @since 0.8.7
*/
class AMDInfoImpl extends CPUIDCPUInfo implements AMDCPUInfo
{
protected static boolean isK6Compatible = false;
protected static boolean isK6_2_Compatible = false;
protected static boolean isK6_3_Compatible = false;
protected static boolean isGeodeCompatible = false;
protected static boolean isAthlonCompatible = false;
protected static boolean isAthlon64Compatible = false;
protected static boolean isBobcatCompatible = false;
protected static boolean isBulldozerCompatible = false;
private static boolean isK6Compatible;
private static boolean isK6_2_Compatible;
private static boolean isK6_3_Compatible;
private static boolean isGeodeCompatible;
private static boolean isAthlonCompatible;
private static boolean isAthlon64Compatible;
private static boolean isBobcatCompatible;
private static boolean isBulldozerCompatible;
// If modelString != null, the cpu is considered correctly identified.
protected static String modelString = null;
private static final String smodel = identifyCPU();
public boolean IsK6Compatible(){ return isK6Compatible; }
@@ -32,28 +35,32 @@ class AMDInfoImpl extends CPUIDCPUInfo implements AMDCPUInfo
public boolean IsBobcatCompatible(){ return isBobcatCompatible; }
public boolean IsBulldozerCompatible(){ return isBulldozerCompatible; }
static
{
identifyCPU();
}
public boolean IsBulldozerCompatible(){ return isBulldozerCompatible; }
public String getCPUModelString() throws UnknownCPUException
{
if (modelString != null)
return modelString;
throw new UnknownCPUException("Unknown AMD CPU; Family="+(CPUID.getCPUFamily() + CPUID.getCPUExtendedFamily())+", Model="+(CPUID.getCPUModel() + CPUID.getCPUExtendedModel()));
if (smodel != null)
return smodel;
throw new UnknownCPUException("Unknown AMD CPU; Family="+CPUID.getCPUFamily() + '/' + CPUID.getCPUExtendedFamily()+
", Model="+CPUID.getCPUModel() + '/' + CPUID.getCPUExtendedModel());
}
private synchronized static void identifyCPU()
private static String identifyCPU()
{
//AMD-family = getCPUFamily()+getCPUExtendedFamily()
//AMD-model = getCPUModel()+getCPUExtendedModel()
//i486 class (Am486, 5x86)
if(CPUID.getCPUFamily() + CPUID.getCPUExtendedFamily() == 4){
switch(CPUID.getCPUModel() + CPUID.getCPUExtendedModel()){
// http://en.wikipedia.org/wiki/Cpuid
String modelString = null;
int family = CPUID.getCPUFamily();
int model = CPUID.getCPUModel();
if (family == 15) {
family += CPUID.getCPUExtendedFamily();
model += CPUID.getCPUExtendedModel() << 4;
}
switch (family) {
//i486 class (Am486, 5x86)
case 4: {
switch (model) {
case 3:
modelString = "486 DX/2";
break;
@@ -72,37 +79,37 @@ class AMDInfoImpl extends CPUIDCPUInfo implements AMDCPUInfo
case 15:
modelString = "Am5x86-WB";
break;
default:
modelString = "AMD 486/586 model " + model;
break;
}
}
}
break;
//i586 class (K5/K6/K6-2/K6-III)
if(CPUID.getCPUFamily() + CPUID.getCPUExtendedFamily() == 5){
// ref: http://support.amd.com/TechDocs/20734.pdf
case 5: {
isK6Compatible = true;
switch(CPUID.getCPUModel() + CPUID.getCPUExtendedModel()){
switch (model) {
case 0:
modelString = "K5/SSA5";
break;
case 1:
modelString = "K5";
break;
case 2:
modelString = "K5";
break;
case 3:
modelString = "K5";
break;
case 4:
isK6Compatible = false;
isGeodeCompatible = true;
modelString = "Geode GX1/GXLV/GXm";
break;
case 5:
isK6Compatible = false;
isGeodeCompatible = true;
modelString = "Geode GX2/LX";
break;
case 6:
modelString = "K6";
isK6Compatible = false;
isGeodeCompatible = true;
modelString = "Geode GX1/GXLV/GXm";
break;
case 5:
isK6Compatible = false;
isGeodeCompatible = true;
modelString = "Geode GX2/LX";
break;
case 6:
case 7:
modelString = "K6";
break;
@@ -119,18 +126,22 @@ class AMDInfoImpl extends CPUIDCPUInfo implements AMDCPUInfo
isK6_2_Compatible = true;
modelString = "K6-2+ or K6-III+";
break;
default:
modelString = "AMD K5/K6 model " + model;
break;
}
}
}
break;
//i686 class (Athlon/Athlon XP/Duron/K7 Sempron)
if(CPUID.getCPUFamily() + CPUID.getCPUExtendedFamily() == 6){
// ref: http://support.amd.com/TechDocs/20734.pdf
case 6: {
isK6Compatible = true;
isK6_2_Compatible = true;
isK6_3_Compatible = true;
isAthlonCompatible = true;
switch(CPUID.getCPUModel() + CPUID.getCPUExtendedModel()){
switch (model) {
case 0:
modelString = "Athlon (250 nm)";
break;
case 1:
modelString = "Athlon (250 nm)";
break;
@@ -155,17 +166,23 @@ class AMDInfoImpl extends CPUIDCPUInfo implements AMDCPUInfo
case 10:
modelString = "Athlon (Barton)";
break;
default:
modelString = "AMD Athlon/Duron model " + model;
break;
}
}
}
break;
//AMD64 class (A64/Opteron/A64 X2/K8 Sempron/Turion/Second-Generation Opteron/Athlon Neo)
if(CPUID.getCPUFamily() + CPUID.getCPUExtendedFamily() == 15){
// ref: http://support.amd.com/TechDocs/33610.PDF
case 15: {
isK6Compatible = true;
isK6_2_Compatible = true;
isK6_3_Compatible = true;
isAthlonCompatible = true;
isAthlon64Compatible = true;
isX64 = true;
switch(CPUID.getCPUModel() + CPUID.getCPUExtendedModel()){
switch (model) {
case 4:
modelString = "Athlon 64/Mobile XP-M";
break;
@@ -182,14 +199,13 @@ class AMDInfoImpl extends CPUIDCPUInfo implements AMDCPUInfo
modelString = "Athlon 64 (Clawhammer S939, 130 nm)";
break;
case 12:
modelString = "Athlon 64/Sempron (Newcastle S754, 130 nm)";
break;
case 14:
modelString = "Athlon 64/Sempron (Newcastle S754, 130 nm)";
break;
case 15:
modelString = "Athlon 64/Sempron (Clawhammer S939, 130 nm)";
break;
// everything below here was broken prior to 0.9.16
case 18:
modelString = "Sempron (Palermo, 90 nm)";
break;
@@ -283,20 +299,22 @@ class AMDInfoImpl extends CPUIDCPUInfo implements AMDCPUInfo
case 193:
modelString = "Athlon 64 FX (Windsor S1207 90 nm)";
break;
default: // is this safe?
modelString = "Athlon 64 (unknown)";
default:
modelString = "AMD Athlon/Duron/Sempron model " + model;
break;
}
}
}
break;
//Stars (Phenom II/Athlon II/Third-Generation Opteron/Opteron 4100 & 6100/Sempron 1xx)
if(CPUID.getCPUFamily() + CPUID.getCPUExtendedFamily() == 16){
case 16: {
isK6Compatible = true;
isK6_2_Compatible = true;
isK6_3_Compatible = true;
isAthlonCompatible = true;
isAthlon64Compatible = true;
isX64 = true;
switch(CPUID.getCPUModel() + CPUID.getCPUExtendedModel()){
switch (model) {
case 2:
modelString = "Phenom / Athlon / Opteron Gen 3 (Barcelona/Agena/Toliman/Kuma, 65 nm)";
break;
@@ -318,24 +336,50 @@ class AMDInfoImpl extends CPUIDCPUInfo implements AMDCPUInfo
case 10:
modelString = "Phenom II X4/X6 (Zosma/Thuban AM3, 45 nm)";
break;
default:
modelString = "AMD Athlon/Opteron model " + model;
break;
}
}
}
break;
//K8 mobile+HT3 (Turion X2/Athlon X2/Sempron)
if(CPUID.getCPUFamily() + CPUID.getCPUExtendedFamily() == 17){
case 17: {
isK6Compatible = true;
isK6_2_Compatible = true;
isK6_3_Compatible = true;
isAthlonCompatible = true;
isAthlon64Compatible = true;
isX64 = true;
switch(CPUID.getCPUModel() + CPUID.getCPUExtendedModel()){
switch (model) {
case 3:
modelString = "AMD Turion X2/Athlon X2/Sempron (Lion/Sable, 65 nm)";
break;
default:
modelString = "AMD Athlon/Turion/Sempron model " + model;
break;
}
}
}
break;
// APUs
// http://en.wikipedia.org/wiki/List_of_AMD_Accelerated_Processing_Unit_microprocessors
// 1st gen Llano high perf / Brazos low power
// 2nd gen Trinity high perf / Brazos 2 low power
// 3rd gen Kaveri high perf / Kabini/Temash low power
case 18: {
isK6Compatible = true;
isK6_2_Compatible = true;
isK6_3_Compatible = true;
isAthlonCompatible = true;
isAthlon64Compatible = true;
isX64 = true;
modelString = "AMD APU model " + model;
}
break;
//Bobcat
if(CPUID.getCPUFamily() + CPUID.getCPUExtendedFamily() == 20){
case 20: {
isK6Compatible = true;
isK6_2_Compatible = true;
isK6_3_Compatible = true;
@@ -343,37 +387,75 @@ class AMDInfoImpl extends CPUIDCPUInfo implements AMDCPUInfo
isAthlon64Compatible = true;
isBobcatCompatible = true;
isX64 = true;
switch(CPUID.getCPUModel() + CPUID.getCPUExtendedModel()){
switch (model) {
case 1:
modelString = "Bobcat APU";
break;
// Case 3 is uncertain but most likely a Bobcat APU
case 3:
modelString = "Bobcat APU";
modelString = "AMD Bobcat APU";
break;
default:
modelString = "AMD Bobcat APU model " + model;
break;
}
}
}
break;
//Bulldozer
if(CPUID.getCPUFamily() + CPUID.getCPUExtendedFamily() == 21){
case 21: {
isK6Compatible = true;
isK6_2_Compatible = true;
isK6_3_Compatible = true;
isAthlonCompatible = true;
isAthlon64Compatible = true;
isBobcatCompatible = true;
isBulldozerCompatible = true;
isBulldozerCompatible = true;
isX64 = true;
switch(CPUID.getCPUModel() + CPUID.getCPUExtendedModel()){
switch (model) {
// 32 nm
case 1:
modelString = "Bulldozer FX-6***/FX-8***";
modelString = "Bulldozer FX-6100/8100";
break;
// 32 nm
case 2:
modelString = "Bulldozer FX-6300/8300";
break;
// 28 nm ?
case 3:
modelString = "Bulldozer FX-6500/8500";
break;
default:
modelString = "AMD Bulldozer model " + model;
break;
}
}
break;
//Jaguar
case 22: {
isK6Compatible = true;
isK6_2_Compatible = true;
isK6_3_Compatible = true;
isAthlonCompatible = true;
isAthlon64Compatible = true;
isBobcatCompatible = true;
isX64 = true;
switch (model) {
case 0:
modelString = "Athlon 5350 APU";
break;
default:
modelString = "AMD Jaguar APU model " + model;
break;
}
}
break;
}
return modelString;
}
public boolean hasX64()
{
return isX64;
}
public boolean hasX64()
{
return isX64;
}
}

View File

@@ -24,8 +24,8 @@ import net.i2p.util.SystemVersion;
/**
* A class for retrieveing details about the CPU using the CPUID assembly instruction.
* A good resource for information about the CPUID instruction can be found here:
* http://www.paradicesoftware.com/specs/cpuid/index.htm
*
* Ref: http://en.wikipedia.org/wiki/Cpuid
*
* @author Iakin
*/
@@ -79,8 +79,11 @@ public class CPUID {
{
loadNative();
}
//A class that can (amongst other things I assume) represent the state of the
//different CPU registers after a call to the CPUID assembly method
/**
* A class that can (amongst other things I assume) represent the state of the
* different CPU registers after a call to the CPUID assembly method
*/
protected static class CPUIDResult {
final int EAX;
final int EBX;
@@ -124,51 +127,75 @@ public class CPUID {
return sb.toString();
}
/** @return 0-15 */
static int getCPUFamily()
{
CPUIDResult c = doCPUID(1);
return (c.EAX >> 8) & 0xf;
}
/** @return 0-15 */
static int getCPUModel()
{
CPUIDResult c = doCPUID(1);
return (c.EAX >> 4) & 0xf;
}
/**
* Only valid if family == 15.
* Left shift by 4 and then add model to get full model.
* @return 0-15
*/
static int getCPUExtendedModel()
{
CPUIDResult c = doCPUID(1);
return (c.EAX >> 16) & 0xf;
}
/** @return 0-15 */
static int getCPUType()
{
CPUIDResult c = doCPUID(1);
return (c.EAX >> 12) & 0xf;
}
/**
* Only valid if family == 15.
* Add family to get full family.
* @return 0-255
*/
static int getCPUExtendedFamily()
{
CPUIDResult c = doCPUID(1);
return (c.EAX >> 20) & 0xff;
}
/** @return 0-15 */
static int getCPUStepping()
{
CPUIDResult c = doCPUID(1);
return c.EAX & 0xf;
}
static int getEDXCPUFlags()
{
CPUIDResult c = doCPUID(1);
return c.EDX;
}
static int getECXCPUFlags()
{
CPUIDResult c = doCPUID(1);
return c.ECX;
}
static int getExtendedEBXCPUFlags()
{
CPUIDResult c = doCPUID(0x80000001);
return c.EBX;
}
static int getExtendedECXCPUFlags()
{
CPUIDResult c = doCPUID(0x80000001);
@@ -182,6 +209,40 @@ public class CPUID {
return c.EDX;
}
/**
* The model name string, up to 48 characters, as reported by
* the processor itself.
*
* @return trimmed string, null if unsupported
* @since 0.9.16
*/
static String getCPUModelName() {
CPUIDResult c = doCPUID(0x80000000);
long maxSupported = c.EAX & 0xFFFFFFFFL;
if (maxSupported < 0x80000004L)
return null;
StringBuilder buf = new StringBuilder(48);
int[] regs = new int[4];
for (int fn = 0x80000002; fn <= 0x80000004; fn++) {
c = doCPUID(fn);
regs[0] = c.EAX;
regs[1] = c.EBX;
regs[2] = c.ECX;
regs[3] = c.EDX;
for (int i = 0; i < 4; i++) {
int reg = regs[i];
for (int j = 0; j < 4; j++) {
char ch = (char) (reg & 0xff);
if (ch == 0)
return buf.toString().trim();
buf.append(ch);
reg >>= 8;
}
}
}
return buf.toString().trim();
}
/**
* Returns a CPUInfo item for the current type of CPU
* If I could I would declare this method in a interface named
@@ -213,9 +274,25 @@ public class CPUID {
System.out.println("**Failed to retrieve CPUInfo. Please verify the existence of jcpuid dll/so**");
}
System.out.println(" **CPUInfo**");
System.out.println("CPU Vendor: " + getCPUVendorID());
System.out.println("CPU Family: " + getCPUFamily());
System.out.println("CPU Model: " + getCPUModel());
String mname = getCPUModelName();
if (mname != null)
System.out.println("CPU Model Name: " + mname);
String vendor = getCPUVendorID();
System.out.println("CPU Vendor: " + vendor);
// http://en.wikipedia.org/wiki/Cpuid
// http://web.archive.org/web/20110307080258/http://www.intel.com/Assets/PDF/appnote/241618.pdf
// http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-2a-manual.pdf
int family = getCPUFamily();
int model = getCPUModel();
if (family == 15 ||
(family == 6 && "GenuineIntel".equals(vendor))) {
model += getCPUExtendedModel() << 4;
}
if (family == 15) {
family += getCPUExtendedFamily();
}
System.out.println("CPU Family: " + family);
System.out.println("CPU Model: " + model);
System.out.println("CPU Stepping: " + getCPUStepping());
System.out.println("CPU Flags: 0x" + Integer.toHexString(getEDXCPUFlags()));
@@ -229,6 +306,7 @@ public class CPUID {
System.out.println("CPU has SSE4.1: " + c.hasSSE41());
System.out.println("CPU has SSE4.2: " + c.hasSSE42());
System.out.println("CPU has SSE4A: " + c.hasSSE4A());
System.out.println("CPU has AES-NI: " + c.hasAES());
if(c instanceof IntelCPUInfo){
System.out.println("\n **Intel-info**");
System.out.println("Is PII-compatible: "+((IntelCPUInfo)c).IsPentium2Compatible());

View File

@@ -45,11 +45,16 @@ public interface IntelCPUInfo extends CPUInfo {
* @return true if the CPU implements at least a Atom level instruction/feature set.
*/
public boolean IsAtomCompatible();
/**
* Supports the SSE 3 instructions.
* @return true if the CPU implements at least a Core2 level instruction/feature set.
*/
public boolean IsCore2Compatible();
/**
* Supports the SSE 3, 4.1, 4.2 instructions.
* In general, this requires 45nm or smaller process.
* @return true if the CPU implements at least a Corei level instruction/feature set.
*/
public boolean IsCoreiCompatible();

View File

@@ -2,22 +2,26 @@ package freenet.support.CPUInformation;
/**
* Moved out of CPUID.java
*
* Ref: https://software.intel.com/en-us/articles/intel-architecture-and-processor-identification-with-cpuid-model-and-family-numbers
* Ref: http://en.wikipedia.org/wiki/List_of_Intel_CPU_microarchitectures
*
* @since 0.8.7
*/
class IntelInfoImpl extends CPUIDCPUInfo implements IntelCPUInfo
{
protected static boolean isPentiumCompatible = false;
protected static boolean isPentiumMMXCompatible = false;
protected static boolean isPentium2Compatible = false;
protected static boolean isPentium3Compatible = false;
protected static boolean isPentium4Compatible = false;
protected static boolean isPentiumMCompatible = false;
protected static boolean isAtomCompatible = false;
protected static boolean isCore2Compatible = false;
protected static boolean isCoreiCompatible = false;
private static boolean isPentiumCompatible;
private static boolean isPentiumMMXCompatible;
private static boolean isPentium2Compatible;
private static boolean isPentium3Compatible;
private static boolean isPentium4Compatible;
private static boolean isPentiumMCompatible;
private static boolean isAtomCompatible;
private static boolean isCore2Compatible;
private static boolean isCoreiCompatible;
// If modelString != null, the cpu is considered correctly identified.
protected static String modelString = null;
private static final String smodel = identifyCPU();
public boolean IsPentiumCompatible(){ return isPentiumCompatible; }
@@ -33,27 +37,45 @@ class IntelInfoImpl extends CPUIDCPUInfo implements IntelCPUInfo
public boolean IsAtomCompatible(){ return isAtomCompatible; }
/**
* Supports the SSE 3 instructions
*/
public boolean IsCore2Compatible(){ return isCore2Compatible; }
/**
* Supports the SSE 3, 4.1, 4.2 instructions.
* In general, this requires 45nm or smaller process.
*/
public boolean IsCoreiCompatible(){ return isCoreiCompatible; }
static
{
identifyCPU();
}
public String getCPUModelString() throws UnknownCPUException
{
if (modelString != null)
return modelString;
throw new UnknownCPUException("Unknown Intel CPU; Family="+CPUID.getCPUFamily()+", Model="+CPUID.getCPUModel());
if (smodel != null)
return smodel;
throw new UnknownCPUException("Unknown Intel CPU; Family="+CPUID.getCPUFamily() + '/' + CPUID.getCPUExtendedFamily()+
", Model="+CPUID.getCPUModel() + '/' + CPUID.getCPUExtendedModel());
}
private synchronized static void identifyCPU()
private static String identifyCPU()
{
if (CPUID.getCPUExtendedModel() == 0){
if(CPUID.getCPUFamily() == 4){
switch(CPUID.getCPUModel()){
// http://en.wikipedia.org/wiki/Cpuid
// http://web.archive.org/web/20110307080258/http://www.intel.com/Assets/PDF/appnote/241618.pdf
// http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-2a-manual.pdf
String modelString = null;
int family = CPUID.getCPUFamily();
int model = CPUID.getCPUModel();
if (family == 15 || family == 6) {
// Intel uses extended model for family = 15 or family = 6,
// which is not what wikipedia says
model += CPUID.getCPUExtendedModel() << 4;
}
if (family == 15) {
family += CPUID.getCPUExtendedFamily();
}
switch (family) {
case 4: {
switch (model) {
case 0:
modelString = "486 DX-25/33";
break;
@@ -81,13 +103,17 @@ class IntelInfoImpl extends CPUIDCPUInfo implements IntelCPUInfo
case 9:
modelString = "486 DX/4-WB";
break;
default:
modelString = "Intel 486/586 model " + model;
break;
}
}
}
if (CPUID.getCPUExtendedModel() == 0){
if(CPUID.getCPUFamily() == 5){
break;
// P5
case 5: {
isPentiumCompatible = true;
switch(CPUID.getCPUModel()){
switch (model) {
case 0:
modelString = "Pentium 60/66 A-step";
break;
@@ -111,20 +137,54 @@ class IntelInfoImpl extends CPUIDCPUInfo implements IntelCPUInfo
isPentiumMMXCompatible = true;
modelString = "Mobile Pentium MMX";
break;
default:
modelString = "Intel Pentium model " + model;
break;
}
}
}
if(CPUID.getCPUFamily() == 6){
if (CPUID.getCPUExtendedModel() == 0){
break;
// P6
case 6: {
isPentiumCompatible = true;
isPentiumMMXCompatible = true;
switch(CPUID.getCPUModel()){
int extmodel = model >> 4;
if (extmodel >= 1) {
isPentium2Compatible = true;
isPentium3Compatible = true;
isPentium4Compatible = true;
isPentiumMCompatible = true;
isCore2Compatible = true;
isX64 = true;
if (extmodel >= 2)
isCoreiCompatible = true;
}
switch (model) {
case 0:
modelString = "Pentium Pro A-step";
break;
case 1:
modelString = "Pentium Pro";
break;
// Spoofed Nehalem by qemu-kvm
// Not in any CPUID charts
// KVM bug?
// # cat /usr/share/kvm/cpus-x86_64.conf | grep 'name = "Nehalem"' -B 1 -A 12
// [cpudef]
// name = "Nehalem"
// level = "2"
// vendor = "GenuineIntel"
// family = "6"
// model = "2"
// stepping = "3"
// feature_edx = "sse2 sse fxsr mmx clflush pse36 pat cmov mca pge mtrr sep apic cx8 mce pae msr tsc pse de fpu"
// feature_ecx = "popcnt sse4.2 sse4.1 cx16 ssse3 sse3"
// extfeature_edx = "i64 syscall xd"
// extfeature_ecx = "lahf_lm"
// xlevel = "0x8000000A"
// model_id = "Intel Core i7 9xx (Nehalem Class Core i7)"
//case 2:
// ...
case 3:
isPentium2Compatible = true;
modelString = "Pentium II (Klamath)";
@@ -150,7 +210,7 @@ class IntelInfoImpl extends CPUIDCPUInfo implements IntelCPUInfo
case 9:
isPentium2Compatible = true;
isPentium3Compatible = true;
isPentiumMCompatible = true;
isPentiumMCompatible = true;
isX64 = true;
modelString = "Pentium M (Banias)";
break;
@@ -167,111 +227,154 @@ class IntelInfoImpl extends CPUIDCPUInfo implements IntelCPUInfo
case 13:
isPentium2Compatible = true;
isPentium3Compatible = true;
isPentiumMCompatible = true;
isPentiumMCompatible = true;
isX64 = true;
modelString = "Core (Yonah)";
break;
case 14:
isPentium2Compatible = true;
isPentium3Compatible = true;
isPentiumMCompatible = true;
isCore2Compatible = true;
isX64 = true;
modelString = "Core 2 (Conroe)";
break;
case 15:
isPentium2Compatible = true;
isPentium3Compatible = true;
isPentiumMCompatible = true;
isPentiumMCompatible = true;
isCore2Compatible = true;
isX64 = true;
modelString = "Core 2 (Conroe)";
break;
}
} else if (CPUID.getCPUExtendedModel() == 1){
isPentiumCompatible = true;
isPentiumMMXCompatible = true;
isPentium2Compatible = true;
isPentium3Compatible = true;
isPentium4Compatible = true;
isPentiumMCompatible = true;
isCore2Compatible = true;
isX64 = true;
switch(CPUID.getCPUModel()){
case 6:
// following are for extended model == 1
// most flags are set above
// Celeron 65 nm
case 0x16:
modelString = "Celeron";
break;
case 10:
isCoreiCompatible = true;
modelString = "Core i7 (45nm)";
// Penryn 45 nm
case 0x17:
modelString = "Core 2 (45nm)";
break;
case 12:
// Nehalem 45 nm
case 0x1a:
isCoreiCompatible = true;
modelString = "Core i7 (45nm)";
break;
// Atom Pineview / Silverthorne 45 nm
case 0x1c:
isAtomCompatible = true;
// Some support SSE3? true for Pineview? TBD...
isCore2Compatible = false;
isPentium4Compatible = false;
isX64 = true;
modelString = "Atom";
break;
case 13:
// Penryn 45 nm
case 0x1d:
isCoreiCompatible = true;
modelString = "Xeon MP (45nm)";
break;
case 14:
// Nehalem 45 nm
case 0x1e:
isCoreiCompatible = true;
modelString = "Core i5/i7 (45nm)";
break;
}
} else if (CPUID.getCPUExtendedModel() == 2){
isPentiumCompatible = true;
isPentiumMMXCompatible = true;
isPentium2Compatible = true;
isPentium3Compatible = true;
isPentium4Compatible = true;
isPentiumMCompatible = true;
isCore2Compatible = true;
isCoreiCompatible = true;
isX64 = true;
switch(CPUID.getCPUModel()){
case 5:
// following are for extended model == 2
// most flags are set above
// isCoreiCompatible = true is the default
// Westmere 32 nm
case 0x25:
modelString = "Core i3 or i5/i7 mobile (32nm)";
break;
case 10:
// Atom Lincroft 45 nm
case 0x26:
isAtomCompatible = true;
// Supports SSE 3
isCoreiCompatible = false;
modelString = "Atom Z600";
break;
// Sandy bridge 32 nm
case 0x2a:
modelString = "Sandy Bridge H/M";
break;
case 0x2b:
modelString = "Core i7/i5 (32nm)";
break;
case 11:
modelString = "Core i7/i5 (32nm)";
break;
case 12:
// Westmere
case 0x2c:
modelString = "Core i7 (32nm)";
break;
case 13:
modelString = "Core i7 Extreme Edition (32nm)";
// Sandy bridge 32 nm
case 0x2d:
modelString = "Sandy Bridge EP";
break;
case 14:
// Nehalem 45 nm
case 0x2e:
modelString = "Xeon MP (45nm)";
break;
case 15:
// Westmere 32 nm
case 0x2f:
modelString = "Xeon MP (32nm)";
break;
}
// following are for extended model == 3
// most flags are set above
// isCoreiCompatible = true is the default
// Atom Cedarview 32 nm
case 0x36:
isAtomCompatible = true;
// Supports SSE 3
isCore2Compatible = false;
modelString = "Atom N2000/D2000";
break;
// Ivy Bridge 22 nm
case 0x3a:
modelString = "Ivy Bridge";
break;
// Haswell 22 nm
case 0x3c:
modelString = "Haswell";
break;
// Broadwell 14 nm
case 0x3d:
modelString = "Broadwell";
break;
// following are for extended model == 4
// most flags are set above
// isCoreiCompatible = true is the default
// Atom Silvermont / Bay Trail / Avoton 22 nm
// Supports SSE 4.2
case 0x4d:
isAtomCompatible = true;
modelString = "Bay Trail / Avoton";
break;
// others
default:
modelString = "Intel model " + model;
break;
} // switch model
} // case 6
break;
case 7: {
// Flags TODO
modelString = "Intel Itanium model " + model;
}
}
if(CPUID.getCPUFamily() == 7){
switch(CPUID.getCPUModel()){
//Itanium.. TODO
}
}
if(CPUID.getCPUFamily() == 15){
if(CPUID.getCPUExtendedFamily() == 0){
break;
// 15 + 0
case 15: {
isPentiumCompatible = true;
isPentiumMMXCompatible = true;
isPentium2Compatible = true;
isPentium3Compatible = true;
isPentium4Compatible = true;
switch(CPUID.getCPUModel()){
switch (model) {
case 0:
modelString = "Pentium IV (180 nm)";
break;
case 1:
modelString = "Pentium IV (180 nm)";
break;
@@ -289,17 +392,23 @@ class IntelInfoImpl extends CPUIDCPUInfo implements IntelCPUInfo
isX64 = true;
modelString = "Pentium IV (65 nm)";
break;
default:
modelString = "Intel Pentium IV model " + model;
break;
}
}
if(CPUID.getCPUExtendedFamily() == 1){
switch(CPUID.getCPUModel()){
// Itanium 2.. TODO
}
break;
// 15 + 1
case 16: {
// Flags TODO
modelString = "Intel Itanium II model " + model;
}
}
return modelString;
}
public boolean hasX64() {
return isX64;
}
public boolean hasX64() {
return isX64;
}
}

View File

@@ -5,65 +5,73 @@ package freenet.support.CPUInformation;
* @since 0.8.7
*/
class VIAInfoImpl extends CPUIDCPUInfo implements VIACPUInfo {
protected static boolean isC3Compatible = false;
protected static boolean isNanoCompatible = false;
private static boolean isC3Compatible;
private static boolean isNanoCompatible;
// If modelString != null, the cpu is considered correctly identified.
protected static String modelString = null;
private static final String smodel = identifyCPU();
public boolean IsC3Compatible(){ return isC3Compatible; }
public boolean IsNanoCompatible(){ return isNanoCompatible; }
static
{
identifyCPU();
}
public boolean IsNanoCompatible(){ return isNanoCompatible; }
public String getCPUModelString()
{
if (modelString != null)
return modelString;
throw new UnknownCPUException("Unknown VIA CPU; Family="+(CPUID.getCPUFamily() + CPUID.getCPUExtendedFamily())+", Model="+(CPUID.getCPUModel() + CPUID.getCPUExtendedModel()));
if (smodel != null)
return smodel;
throw new UnknownCPUException("Unknown VIA CPU; Family="+CPUID.getCPUFamily() + '/' + CPUID.getCPUExtendedFamily()+
", Model="+CPUID.getCPUModel() + '/' + CPUID.getCPUExtendedModel());
}
public boolean hasX64()
{
return false;
}
public boolean hasX64()
{
return false;
}
private synchronized static void identifyCPU()
{
if(CPUID.getCPUFamily() == 6){
isC3Compatible = true; // Possibly not optimal
switch(CPUID.getCPUModel()){
case 5:
modelString = "Cyrix M2";
break;
case 6:
modelString = "C5 A/B";
break;
case 7:
modelString = "C5 C";
break;
case 8:
modelString = "C5 N";
break;
case 9:
modelString = "C5 XL/P";
break;
case 10:
modelString = "C5 J";
break;
case 15:
isNanoCompatible = true;
modelString = "Nano";
break;
private static String identifyCPU()
{
// http://en.wikipedia.org/wiki/Cpuid
String modelString = null;
int family = CPUID.getCPUFamily();
int model = CPUID.getCPUModel();
if (family == 15) {
family += CPUID.getCPUExtendedFamily();
model += CPUID.getCPUExtendedModel() << 4;
}
if (family == 6) {
isC3Compatible = true; // Possibly not optimal
switch (model) {
case 5:
modelString = "Cyrix M2";
break;
case 6:
modelString = "C5 A/B";
break;
case 7:
modelString = "C5 C";
break;
case 8:
modelString = "C5 N";
break;
case 9:
modelString = "C5 XL/P";
break;
case 10:
modelString = "C5 J";
break;
case 15:
isNanoCompatible = true;
modelString = "Nano";
break;
default:
modelString = "Via model " + model;
break;
}
}
}
return modelString;
}
}

View File

@@ -16,7 +16,7 @@ package net.i2p;
public class CoreVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = "0.9.14.1";
public final static String VERSION = "0.9.15";
public static void main(String args[]) {
System.out.println("I2P Core version: " + VERSION);

View File

@@ -16,7 +16,7 @@ import net.i2p.I2PAppContext;
* @since 0.9.14
*/
public class DomainSocketFactory {
public static String I2CP_SOCKET_ADDRESS = "net.i2p.client.i2cp";
public static final String I2CP_SOCKET_ADDRESS = "net.i2p.client.i2cp";
/**
* @throws UnsupportedOperationException always

View File

@@ -899,6 +899,8 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
* Close the socket carefully.
*/
private void closeSocket() {
if (_log.shouldLog(Log.INFO))
_log.info(getPrefix() + "Closing the socket", new Exception("closeSocket"));
synchronized(_stateLock) {
changeState(State.CLOSING);
locked_closeSocket();
@@ -911,7 +913,6 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
* Caller must change state.
*/
private void locked_closeSocket() {
if (_log.shouldLog(Log.INFO)) _log.info(getPrefix() + "Closing the socket", new Exception("closeSocket"));
if (_reader != null) {
_reader.stopReading();
_reader = null;

View File

@@ -347,10 +347,10 @@ public class KeyGenerator {
try { Thread.sleep(1000); } catch (InterruptedException ie) {}
int runs = 200; // warmup
for (int j = 0; j < 2; j++) {
for (int i = 0; i <= 100; i++) {
SigType type = SigType.getByCode(i);
if (type == null)
break;
for (SigType type : SigType.values()) {
if (!type.isAvailable()) {
System.out.println("Skipping unavailable: " + type);
}
try {
System.out.println("Testing " + type);
testSig(type, runs);
@@ -365,9 +365,19 @@ public class KeyGenerator {
private static void testSig(SigType type, int runs) throws GeneralSecurityException {
byte src[] = new byte[512];
double gtime = 0;
long stime = 0;
long vtime = 0;
SimpleDataStructure keys[] = KeyGenerator.getInstance().generateSigningKeys(type);
SimpleDataStructure keys[] = null;
long st = System.nanoTime();
// RSA super slow, limit to 5
int genruns = (type.getBaseAlgorithm() == SigAlgo.RSA) ? Math.min(runs, 5) : runs;
for (int i = 0; i < genruns; i++) {
keys = KeyGenerator.getInstance().generateSigningKeys(type);
}
long en = System.nanoTime();
gtime = ((en - st) / (1000*1000d)) / genruns;
System.out.println(type + " key gen " + genruns + " times: " + gtime + " ms each");
SigningPublicKey pubkey = (SigningPublicKey) keys[0];
SigningPrivateKey privkey = (SigningPrivateKey) keys[1];
SigningPublicKey pubkey2 = getSigningPublicKey(privkey);

View File

@@ -212,6 +212,7 @@ public class SigUtil {
/**
* @return JAVA EdDSA public key!
* @since 0.9.15
*/
public static EdDSAPublicKey toJavaEdDSAKey(SigningPublicKey pk)
throws GeneralSecurityException {
@@ -230,6 +231,7 @@ public class SigUtil {
/**
* @return JAVA EdDSA private key!
* @since 0.9.15
*/
public static EdDSAPrivateKey toJavaEdDSAKey(SigningPrivateKey pk)
throws GeneralSecurityException {
@@ -246,6 +248,9 @@ public class SigUtil {
return rv;
}
/**
* @since 0.9.15
*/
private static EdDSAPublicKey cvtToJavaEdDSAKey(SigningPublicKey pk)
throws GeneralSecurityException {
try {
@@ -256,6 +261,9 @@ public class SigUtil {
}
}
/**
* @since 0.9.15
*/
private static EdDSAPrivateKey cvtToJavaEdDSAKey(SigningPrivateKey pk)
throws GeneralSecurityException {
try {
@@ -266,11 +274,17 @@ public class SigUtil {
}
}
/**
* @since 0.9.15
*/
public static SigningPublicKey fromJavaKey(EdDSAPublicKey pk, SigType type)
throws GeneralSecurityException {
return new SigningPublicKey(type, pk.getAbyte());
}
/**
* @since 0.9.15
*/
public static SigningPrivateKey fromJavaKey(EdDSAPrivateKey pk, SigType type)
throws GeneralSecurityException {
return new SigningPrivateKey(type, pk.getSeed());

View File

@@ -14,6 +14,7 @@ import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable;
import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec;
import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec;
import net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec;
import net.i2p.util.RandomSource;
/**
* Default strength is 256
@@ -60,7 +61,7 @@ public class KeyPairGenerator extends KeyPairGeneratorSpi {
public KeyPair generateKeyPair() {
if (!initialized)
initialize(DEFAULT_STRENGTH, new SecureRandom());
initialize(DEFAULT_STRENGTH, RandomSource.getInstance());
byte[] seed = new byte[edParams.getCurve().getField().getb()/8];
random.nextBytes(seed);

View File

@@ -11,7 +11,9 @@ package net.i2p.crypto.eddsa.math;
public abstract class Encoding {
protected Field f;
public void setField(Field f) {
public synchronized void setField(Field f) {
if (this.f != null)
throw new IllegalStateException("already set");
this.f = f;
}

View File

@@ -13,7 +13,7 @@ public class Ed25519FieldElement extends FieldElement {
/**
* Variable is package private for encoding.
*/
int[] t;
final int[] t;
public Ed25519FieldElement(Field f, int[] t) {
super(f);
@@ -22,11 +22,11 @@ public class Ed25519FieldElement extends FieldElement {
this.t = t;
}
private static final byte[] zero = new byte[32];
private static final byte[] ZERO = new byte[32];
public boolean isNonZero() {
byte[] s = toByteArray();
return Utils.equal(s, zero) == 1;
return Utils.equal(s, ZERO) == 1;
}
/**
@@ -42,47 +42,10 @@ public class Ed25519FieldElement extends FieldElement {
*/
public FieldElement add(FieldElement val) {
int[] g = ((Ed25519FieldElement)val).t;
int f0 = t[0];
int f1 = t[1];
int f2 = t[2];
int f3 = t[3];
int f4 = t[4];
int f5 = t[5];
int f6 = t[6];
int f7 = t[7];
int f8 = t[8];
int f9 = t[9];
int g0 = g[0];
int g1 = g[1];
int g2 = g[2];
int g3 = g[3];
int g4 = g[4];
int g5 = g[5];
int g6 = g[6];
int g7 = g[7];
int g8 = g[8];
int g9 = g[9];
int h0 = f0 + g0;
int h1 = f1 + g1;
int h2 = f2 + g2;
int h3 = f3 + g3;
int h4 = f4 + g4;
int h5 = f5 + g5;
int h6 = f6 + g6;
int h7 = f7 + g7;
int h8 = f8 + g8;
int h9 = f9 + g9;
int[] h = new int[10];
h[0] = h0;
h[1] = h1;
h[2] = h2;
h[3] = h3;
h[4] = h4;
h[5] = h5;
h[6] = h6;
h[7] = h7;
h[8] = h8;
h[9] = h9;
for (int i = 0; i < 10; i++) {
h[i] = t[i] + g[i];
}
return new Ed25519FieldElement(f, h);
}
@@ -99,47 +62,10 @@ public class Ed25519FieldElement extends FieldElement {
**/
public FieldElement subtract(FieldElement val) {
int[] g = ((Ed25519FieldElement)val).t;
int f0 = t[0];
int f1 = t[1];
int f2 = t[2];
int f3 = t[3];
int f4 = t[4];
int f5 = t[5];
int f6 = t[6];
int f7 = t[7];
int f8 = t[8];
int f9 = t[9];
int g0 = g[0];
int g1 = g[1];
int g2 = g[2];
int g3 = g[3];
int g4 = g[4];
int g5 = g[5];
int g6 = g[6];
int g7 = g[7];
int g8 = g[8];
int g9 = g[9];
int h0 = f0 - g0;
int h1 = f1 - g1;
int h2 = f2 - g2;
int h3 = f3 - g3;
int h4 = f4 - g4;
int h5 = f5 - g5;
int h6 = f6 - g6;
int h7 = f7 - g7;
int h8 = f8 - g8;
int h9 = f9 - g9;
int[] h = new int[10];
h[0] = h0;
h[1] = h1;
h[2] = h2;
h[3] = h3;
h[4] = h4;
h[5] = h5;
h[6] = h6;
h[7] = h7;
h[8] = h8;
h[9] = h9;
for (int i = 0; i < 10; i++) {
h[i] = t[i] - g[i];
}
return new Ed25519FieldElement(f, h);
}
@@ -153,37 +79,10 @@ public class Ed25519FieldElement extends FieldElement {
* |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
*/
public FieldElement negate() {
int f0 = t[0];
int f1 = t[1];
int f2 = t[2];
int f3 = t[3];
int f4 = t[4];
int f5 = t[5];
int f6 = t[6];
int f7 = t[7];
int f8 = t[8];
int f9 = t[9];
int h0 = -f0;
int h1 = -f1;
int h2 = -f2;
int h3 = -f3;
int h4 = -f4;
int h5 = -f5;
int h6 = -f6;
int h7 = -f7;
int h8 = -f8;
int h9 = -f9;
int[] h = new int[10];
h[0] = h0;
h[1] = h1;
h[2] = h2;
h[3] = h3;
h[4] = h4;
h[5] = h5;
h[6] = h6;
h[7] = h7;
h[8] = h8;
h[9] = h9;
for (int i = 0; i < 10; i++) {
h[i] = - t[i];
}
return new Ed25519FieldElement(f, h);
}
@@ -947,7 +846,11 @@ public class Ed25519FieldElement extends FieldElement {
@Override
public int hashCode() {
return t.hashCode(); // TODO should this be something else?
int rv = 0;
for (int i = 0; i < 10; i++) {
rv ^= t[i];
}
return rv;
}
@Override

View File

@@ -88,7 +88,7 @@ public class Ed25519LittleEndianEncoding extends Encoding {
*/
byte[] s = new byte[32];
s[0] = (byte) (h0 >> 0);
s[0] = (byte) h0;
s[1] = (byte) (h0 >> 8);
s[2] = (byte) (h0 >> 16);
s[3] = (byte) ((h0 >> 24) | (h1 << 2));
@@ -104,7 +104,7 @@ public class Ed25519LittleEndianEncoding extends Encoding {
s[13] = (byte) (h4 >> 2);
s[14] = (byte) (h4 >> 10);
s[15] = (byte) (h4 >> 18);
s[16] = (byte) (h5 >> 0);
s[16] = (byte) h5;
s[17] = (byte) (h5 >> 8);
s[18] = (byte) (h5 >> 16);
s[19] = (byte) ((h5 >> 24) | (h6 << 1));
@@ -123,14 +123,14 @@ public class Ed25519LittleEndianEncoding extends Encoding {
return s;
}
private static long load_3(byte[] in, int offset) {
static int load_3(byte[] in, int offset) {
int result = in[offset++] & 0xff;
result |= (in[offset++] & 0xff) << 8;
result |= (in[offset] & 0xff) << 16;
return result;
}
private static long load_4(byte[] in, int offset) {
static long load_4(byte[] in, int offset) {
int result = in[offset++] & 0xff;
result |= (in[offset++] & 0xff) << 8;
result |= (in[offset++] & 0xff) << 16;

View File

@@ -1,22 +1,10 @@
package net.i2p.crypto.eddsa.math.ed25519;
import net.i2p.crypto.eddsa.math.ScalarOps;
import static net.i2p.crypto.eddsa.math.ed25519.Ed25519LittleEndianEncoding.load_3;
import static net.i2p.crypto.eddsa.math.ed25519.Ed25519LittleEndianEncoding.load_4;
public class Ed25519ScalarOps implements ScalarOps {
private static long load_3(byte[] in, int offset) {
int result = in[offset++] & 0xff;
result |= (in[offset++] & 0xff) << 8;
result |= (in[offset] & 0xff) << 16;
return result;
}
private static long load_4(byte[] in, int offset) {
int result = in[offset++] & 0xff;
result |= (in[offset++] & 0xff) << 8;
result |= (in[offset++] & 0xff) << 16;
result |= in[offset] << 24;
return ((long)result) & 0xffffffffL;
}
/**
* Input:<br>
@@ -75,7 +63,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s14 -= s23 * 997805;
s15 += s23 * 136657;
s16 -= s23 * 683901;
s23 = 0;
// not used again
//s23 = 0;
s10 += s22 * 666643;
s11 += s22 * 470296;
@@ -83,7 +72,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s13 -= s22 * 997805;
s14 += s22 * 136657;
s15 -= s22 * 683901;
s22 = 0;
// not used again
//s22 = 0;
s9 += s21 * 666643;
s10 += s21 * 470296;
@@ -91,7 +81,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s12 -= s21 * 997805;
s13 += s21 * 136657;
s14 -= s21 * 683901;
s21 = 0;
// not used again
//s21 = 0;
s8 += s20 * 666643;
s9 += s20 * 470296;
@@ -99,7 +90,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s11 -= s20 * 997805;
s12 += s20 * 136657;
s13 -= s20 * 683901;
s20 = 0;
// not used again
//s20 = 0;
s7 += s19 * 666643;
s8 += s19 * 470296;
@@ -107,7 +99,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s10 -= s19 * 997805;
s11 += s19 * 136657;
s12 -= s19 * 683901;
s19 = 0;
// not used again
//s19 = 0;
s6 += s18 * 666643;
s7 += s18 * 470296;
@@ -115,7 +108,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s9 -= s18 * 997805;
s10 += s18 * 136657;
s11 -= s18 * 683901;
s18 = 0;
// not used again
//s18 = 0;
carry6 = (s6 + (1<<20)) >> 21; s7 += carry6; s6 -= carry6 << 21;
carry8 = (s8 + (1<<20)) >> 21; s9 += carry8; s8 -= carry8 << 21;
@@ -136,7 +130,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s8 -= s17 * 997805;
s9 += s17 * 136657;
s10 -= s17 * 683901;
s17 = 0;
// not used again
//s17 = 0;
s4 += s16 * 666643;
s5 += s16 * 470296;
@@ -144,7 +139,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s7 -= s16 * 997805;
s8 += s16 * 136657;
s9 -= s16 * 683901;
s16 = 0;
// not used again
//s16 = 0;
s3 += s15 * 666643;
s4 += s15 * 470296;
@@ -152,7 +148,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s6 -= s15 * 997805;
s7 += s15 * 136657;
s8 -= s15 * 683901;
s15 = 0;
// not used again
//s15 = 0;
s2 += s14 * 666643;
s3 += s14 * 470296;
@@ -160,7 +157,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s5 -= s14 * 997805;
s6 += s14 * 136657;
s7 -= s14 * 683901;
s14 = 0;
// not used again
//s14 = 0;
s1 += s13 * 666643;
s2 += s13 * 470296;
@@ -168,7 +166,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s4 -= s13 * 997805;
s5 += s13 * 136657;
s6 -= s13 * 683901;
s13 = 0;
// not used again
//s13 = 0;
s0 += s12 * 666643;
s1 += s12 * 470296;
@@ -176,7 +175,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s3 -= s12 * 997805;
s4 += s12 * 136657;
s5 -= s12 * 683901;
s12 = 0;
// set below
//s12 = 0;
carry0 = (s0 + (1<<20)) >> 21; s1 += carry0; s0 -= carry0 << 21;
carry2 = (s2 + (1<<20)) >> 21; s3 += carry2; s2 -= carry2 << 21;
@@ -190,7 +190,8 @@ public class Ed25519ScalarOps implements ScalarOps {
carry5 = (s5 + (1<<20)) >> 21; s6 += carry5; s5 -= carry5 << 21;
carry7 = (s7 + (1<<20)) >> 21; s8 += carry7; s7 -= carry7 << 21;
carry9 = (s9 + (1<<20)) >> 21; s10 += carry9; s9 -= carry9 << 21;
carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21;
//carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21;
carry11 = (s11 + (1<<20)) >> 21; s12 = carry11; s11 -= carry11 << 21;
s0 += s12 * 666643;
s1 += s12 * 470296;
@@ -198,7 +199,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s3 -= s12 * 997805;
s4 += s12 * 136657;
s5 -= s12 * 683901;
s12 = 0;
// set below
//s12 = 0;
carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21;
carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21;
@@ -211,7 +213,8 @@ public class Ed25519ScalarOps implements ScalarOps {
carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21;
carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21;
carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21;
carry11 = s11 >> 21; s12 += carry11; s11 -= carry11 << 21;
//carry11 = s11 >> 21; s12 += carry11; s11 -= carry11 << 21;
carry11 = s11 >> 21; s12 = carry11; s11 -= carry11 << 21;
s0 += s12 * 666643;
s1 += s12 * 470296;
@@ -219,7 +222,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s3 -= s12 * 997805;
s4 += s12 * 136657;
s5 -= s12 * 683901;
s12 = 0;
// not used again
//s12 = 0;
carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21;
carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21;
@@ -234,7 +238,7 @@ public class Ed25519ScalarOps implements ScalarOps {
carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21;
byte[] result = new byte[32];
result[0] = (byte) (s0 >> 0);
result[0] = (byte) s0;
result[1] = (byte) (s0 >> 8);
result[2] = (byte) ((s0 >> 16) | (s1 << 5));
result[3] = (byte) (s1 >> 3);
@@ -255,7 +259,7 @@ public class Ed25519ScalarOps implements ScalarOps {
result[18] = (byte) ((s6 >> 18) | (s7 << 3));
result[19] = (byte) (s7 >> 5);
result[20] = (byte) (s7 >> 13);
result[21] = (byte) (s8 >> 0);
result[21] = (byte) s8;
result[22] = (byte) (s8 >> 8);
result[23] = (byte) ((s8 >> 16) | (s9 << 5));
result[24] = (byte) (s9 >> 3);
@@ -388,7 +392,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s20 = a9*b11 + a10*b10 + a11*b9;
s21 = a10*b11 + a11*b10;
s22 = a11*b11;
s23 = 0;
// set below
//s23 = 0;
carry0 = (s0 + (1<<20)) >> 21; s1 += carry0; s0 -= carry0 << 21;
carry2 = (s2 + (1<<20)) >> 21; s3 += carry2; s2 -= carry2 << 21;
@@ -401,7 +406,8 @@ public class Ed25519ScalarOps implements ScalarOps {
carry16 = (s16 + (1<<20)) >> 21; s17 += carry16; s16 -= carry16 << 21;
carry18 = (s18 + (1<<20)) >> 21; s19 += carry18; s18 -= carry18 << 21;
carry20 = (s20 + (1<<20)) >> 21; s21 += carry20; s20 -= carry20 << 21;
carry22 = (s22 + (1<<20)) >> 21; s23 += carry22; s22 -= carry22 << 21;
//carry22 = (s22 + (1<<20)) >> 21; s23 += carry22; s22 -= carry22 << 21;
carry22 = (s22 + (1<<20)) >> 21; s23 = carry22; s22 -= carry22 << 21;
carry1 = (s1 + (1<<20)) >> 21; s2 += carry1; s1 -= carry1 << 21;
carry3 = (s3 + (1<<20)) >> 21; s4 += carry3; s3 -= carry3 << 21;
@@ -421,7 +427,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s14 -= s23 * 997805;
s15 += s23 * 136657;
s16 -= s23 * 683901;
s23 = 0;
// not used again
//s23 = 0;
s10 += s22 * 666643;
s11 += s22 * 470296;
@@ -429,7 +436,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s13 -= s22 * 997805;
s14 += s22 * 136657;
s15 -= s22 * 683901;
s22 = 0;
// not used again
//s22 = 0;
s9 += s21 * 666643;
s10 += s21 * 470296;
@@ -437,7 +445,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s12 -= s21 * 997805;
s13 += s21 * 136657;
s14 -= s21 * 683901;
s21 = 0;
// not used again
//s21 = 0;
s8 += s20 * 666643;
s9 += s20 * 470296;
@@ -445,7 +454,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s11 -= s20 * 997805;
s12 += s20 * 136657;
s13 -= s20 * 683901;
s20 = 0;
// not used again
//s20 = 0;
s7 += s19 * 666643;
s8 += s19 * 470296;
@@ -453,7 +463,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s10 -= s19 * 997805;
s11 += s19 * 136657;
s12 -= s19 * 683901;
s19 = 0;
// not used again
//s19 = 0;
s6 += s18 * 666643;
s7 += s18 * 470296;
@@ -461,7 +472,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s9 -= s18 * 997805;
s10 += s18 * 136657;
s11 -= s18 * 683901;
s18 = 0;
// not used again
//s18 = 0;
carry6 = (s6 + (1<<20)) >> 21; s7 += carry6; s6 -= carry6 << 21;
carry8 = (s8 + (1<<20)) >> 21; s9 += carry8; s8 -= carry8 << 21;
@@ -482,7 +494,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s8 -= s17 * 997805;
s9 += s17 * 136657;
s10 -= s17 * 683901;
s17 = 0;
// not used again
//s17 = 0;
s4 += s16 * 666643;
s5 += s16 * 470296;
@@ -490,7 +503,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s7 -= s16 * 997805;
s8 += s16 * 136657;
s9 -= s16 * 683901;
s16 = 0;
// not used again
//s16 = 0;
s3 += s15 * 666643;
s4 += s15 * 470296;
@@ -498,7 +512,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s6 -= s15 * 997805;
s7 += s15 * 136657;
s8 -= s15 * 683901;
s15 = 0;
// not used again
//s15 = 0;
s2 += s14 * 666643;
s3 += s14 * 470296;
@@ -506,7 +521,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s5 -= s14 * 997805;
s6 += s14 * 136657;
s7 -= s14 * 683901;
s14 = 0;
// not used again
//s14 = 0;
s1 += s13 * 666643;
s2 += s13 * 470296;
@@ -514,7 +530,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s4 -= s13 * 997805;
s5 += s13 * 136657;
s6 -= s13 * 683901;
s13 = 0;
// not used again
//s13 = 0;
s0 += s12 * 666643;
s1 += s12 * 470296;
@@ -522,7 +539,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s3 -= s12 * 997805;
s4 += s12 * 136657;
s5 -= s12 * 683901;
s12 = 0;
// set below
//s12 = 0;
carry0 = (s0 + (1<<20)) >> 21; s1 += carry0; s0 -= carry0 << 21;
carry2 = (s2 + (1<<20)) >> 21; s3 += carry2; s2 -= carry2 << 21;
@@ -536,7 +554,8 @@ public class Ed25519ScalarOps implements ScalarOps {
carry5 = (s5 + (1<<20)) >> 21; s6 += carry5; s5 -= carry5 << 21;
carry7 = (s7 + (1<<20)) >> 21; s8 += carry7; s7 -= carry7 << 21;
carry9 = (s9 + (1<<20)) >> 21; s10 += carry9; s9 -= carry9 << 21;
carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21;
//carry11 = (s11 + (1<<20)) >> 21; s12 += carry11; s11 -= carry11 << 21;
carry11 = (s11 + (1<<20)) >> 21; s12 = carry11; s11 -= carry11 << 21;
s0 += s12 * 666643;
s1 += s12 * 470296;
@@ -544,7 +563,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s3 -= s12 * 997805;
s4 += s12 * 136657;
s5 -= s12 * 683901;
s12 = 0;
// set below
//s12 = 0;
carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21;
carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21;
@@ -557,7 +577,8 @@ public class Ed25519ScalarOps implements ScalarOps {
carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 << 21;
carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 << 21;
carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21;
carry11 = s11 >> 21; s12 += carry11; s11 -= carry11 << 21;
//carry11 = s11 >> 21; s12 += carry11; s11 -= carry11 << 21;
carry11 = s11 >> 21; s12 = carry11; s11 -= carry11 << 21;
s0 += s12 * 666643;
s1 += s12 * 470296;
@@ -565,7 +586,8 @@ public class Ed25519ScalarOps implements ScalarOps {
s3 -= s12 * 997805;
s4 += s12 * 136657;
s5 -= s12 * 683901;
s12 = 0;
// not used again
//s12 = 0;
carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 << 21;
carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 << 21;
@@ -580,7 +602,7 @@ public class Ed25519ScalarOps implements ScalarOps {
carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 << 21;
byte[] result = new byte[32];
result[0] = (byte) (s0 >> 0);
result[0] = (byte) s0;
result[1] = (byte) (s0 >> 8);
result[2] = (byte) ((s0 >> 16) | (s1 << 5));
result[3] = (byte) (s1 >> 3);
@@ -601,7 +623,7 @@ public class Ed25519ScalarOps implements ScalarOps {
result[18] = (byte) ((s6 >> 18) | (s7 << 3));
result[19] = (byte) (s7 >> 5);
result[20] = (byte) (s7 >> 13);
result[21] = (byte) (s8 >> 0);
result[21] = (byte) s8;
result[22] = (byte) (s8 >> 8);
result[23] = (byte) ((s8 >> 16) | (s9 << 5));
result[24] = (byte) (s9 >> 3);

View File

@@ -264,6 +264,8 @@ public class Base64 {
private static void decode(InputStream in, OutputStream out) throws IOException {
byte decoded[] = decode(new String(read(in)));
if (decoded == null)
throw new IOException("Invalid base 64 string");
out.write(decoded);
}

View File

@@ -140,10 +140,13 @@ class LogWriter implements Runnable {
/**
* File may not exist or have old logs in it if not opened yet
*/
public String currentFile() {
return _currentFile != null ? _currentFile.getAbsolutePath()
//: "uninitialized";
: getNextFile(_manager.getBaseLogfilename()).getAbsolutePath();
public synchronized String currentFile() {
if (_currentFile != null)
return _currentFile.getAbsolutePath();
String rv = getNextFile().getAbsolutePath();
// so it doesn't increment every time we call this
_rotationNum = -1;
return rv;
}
private void rereadConfig() {
@@ -173,7 +176,7 @@ class LogWriter implements Runnable {
}
}
private void writeRecord(String val) {
private synchronized void writeRecord(String val) {
if (val == null) return;
if (_currentOut == null) {
rotateFile();
@@ -200,10 +203,10 @@ class LogWriter implements Runnable {
/**
* Rotate to the next file (or the first file if this is the first call)
*
* Caller must synch
*/
private void rotateFile() {
String pattern = _manager.getBaseLogfilename();
File f = getNextFile(pattern);
File f = getNextFile();
_currentFile = f;
_numBytesInCurrentFile = 0;
File parent = f.getParentFile();
@@ -242,8 +245,10 @@ class LogWriter implements Runnable {
/**
* Get the next file in the rotation
*
* Caller must synch
*/
private File getNextFile(String pattern) {
private File getNextFile() {
String pattern = _manager.getBaseLogfilename();
File f = new File(pattern);
File base = null;
if (!f.isAbsolute())
@@ -274,6 +279,7 @@ class LogWriter implements Runnable {
/**
* Retrieve the first file, updating the rotation number accordingly
*
* Caller must synch
*/
private File getFirstFile(File base, String pattern, int max) {
for (int i = 0; i < max; i++) {

View File

@@ -23,9 +23,6 @@ public class DataTestSuite {
suite.addTestSuite(PayloadTest.class);
suite.addTestSuite(PrivateKeyTest.class);
suite.addTestSuite(PublicKeyTest.class);
suite.addTestSuite(RouterAddressTest.class);
suite.addTestSuite(RouterIdentityTest.class);
suite.addTestSuite(RouterInfoTest.class);
suite.addTestSuite(SessionKeyTest.class);
suite.addTestSuite(SignatureTest.class);
suite.addTestSuite(SigningPrivateKeyTest.class);

View File

@@ -1,106 +0,0 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayOutputStream;
import java.util.Properties;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class RouterAddressTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
RouterAddress addr = new RouterAddress();
byte data[] = new byte[32];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
addr.setCost(42);
//addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
Properties options = new Properties();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
addr.setTransportStyle("Blah");
return addr;
}
public DataStructure createStructureToRead() { return new RouterAddress(); }
public void testSetNullOptions(){
RouterAddress addr = new RouterAddress();
boolean error = false;
try{
addr.setOptions(null);
}catch(NullPointerException dfe){
error = true;
}
assertTrue(error);
}
public void testSetOptionsAgain(){
RouterAddress addr = new RouterAddress();
Properties options = new Properties();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
options.setProperty("portnum", "2345");
boolean error = false;
try{
addr.setOptions(options);
}catch(IllegalStateException dfe){
error = true;
}
assertTrue(error);
}
public void testBadWrite() throws Exception{
RouterAddress addr = new RouterAddress();
boolean error = false;
try{
addr.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testNullEquals(){
RouterAddress addr = new RouterAddress();
byte data[] = new byte[32];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
addr.setCost(42);
//addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
Properties options = new Properties();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
addr.setTransportStyle("Blah");
assertFalse(addr.equals(null));
assertFalse(addr.equals(""));
}
public void testToString(){
RouterAddress addr = new RouterAddress();
byte data[] = new byte[32];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
addr.setCost(42);
//addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
Properties options = new Properties();
options.setProperty("hostname", "localhost");
options.setProperty("portnum", "1234");
addr.setOptions(options);
addr.setTransportStyle("Blah");
String ret = addr.toString();
//assertEquals("[RouterAddress: \n\tTransportStyle: Blah\n\tCost: 42\n\tExpiration: Fri Jan 02 00:00:00 UTC 1970\n\tOptions: #: 2\n\t\t[hostname] = [localhost]\n\t\t[portnum] = [1234]]", ret);
assertEquals("[RouterAddress: \n\tType: Blah\n\tCost: 42\n\tOptions (2):\n\t\t[hostname] = [localhost]\n\t\t[portnum] = [1234]]", ret);
}
}

View File

@@ -1,116 +0,0 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.io.ByteArrayOutputStream;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class RouterIdentityTest extends StructureTest {
public DataStructure createDataStructure() throws DataFormatException {
RouterIdentity ident = new RouterIdentity();
Certificate cert = (Certificate)(new CertificateTest()).createDataStructure();
ident.setCertificate(cert);
PublicKey pk = (PublicKey)(new PublicKeyTest()).createDataStructure();
ident.setPublicKey(pk);
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
ident.setSigningPublicKey(k);
return ident;
}
public DataStructure createStructureToRead() { return new RouterIdentity(); }
public void testNullCert() throws Exception{
RouterIdentity ident = new RouterIdentity();
ident.setCertificate(null);
PublicKey pk = (PublicKey)(new PublicKeyTest()).createDataStructure();
ident.setPublicKey(pk);
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
ident.setSigningPublicKey(k);
boolean error = false;
try{
ident.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testNullPublicKey() throws Exception{
RouterIdentity ident = new RouterIdentity();
Certificate cert = (Certificate)(new CertificateTest()).createDataStructure();
ident.setCertificate(cert);
ident.setPublicKey(null);
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
ident.setSigningPublicKey(k);
boolean error = false;
try{
ident.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testNullSigningKey() throws Exception{
RouterIdentity ident = new RouterIdentity();
Certificate cert = (Certificate)(new CertificateTest()).createDataStructure();
ident.setCertificate(cert);
PublicKey pk = (PublicKey)(new PublicKeyTest()).createDataStructure();
ident.setPublicKey(pk);
ident.setSigningPublicKey(null);
boolean error = false;
try{
ident.writeBytes(new ByteArrayOutputStream());
}catch(DataFormatException dfe){
error = true;
}
assertTrue(error);
}
public void testNullEquals() throws Exception{
RouterIdentity ident = new RouterIdentity();
assertFalse(ident.equals(null));
}
public void testCalculatedHash() throws Exception{
RouterIdentity ident = new RouterIdentity();
Certificate cert = (Certificate)(new CertificateTest()).createDataStructure();
ident.setCertificate(cert);
PublicKey pk = (PublicKey)(new PublicKeyTest()).createDataStructure();
ident.setPublicKey(pk);
SigningPublicKey k = (SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure();
ident.setSigningPublicKey(k);
ident.calculateHash();
ident.calculateHash();
ident.calculateHash();
ident.calculateHash();
ident.calculateHash();
}
public void testBadHash() throws Exception {
RouterIdentity ident = new RouterIdentity();
boolean error = false;
try {
ident.getHash();
} catch (IllegalStateException ise) {
error = true;
}
assertTrue(error);
}
}

View File

@@ -1,73 +0,0 @@
package net.i2p.data;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
import java.util.HashSet;
import java.util.Properties;
import net.i2p.crypto.KeyGenerator;
import net.i2p.util.Log;
/**
* Test harness for loading / storing Hash objects
*
* @author jrandom
*/
public class RouterInfoTest extends StructureTest {
private final static Log _log = new Log(RouterInfoTest.class);
public DataStructure createDataStructure() throws DataFormatException {
RouterInfo info = new RouterInfo();
HashSet<RouterAddress> addresses = new HashSet<RouterAddress>();
DataStructure structure = (new RouterAddressTest()).createDataStructure();
addresses.add((RouterAddress) structure);
info.setAddresses(addresses);
PublicKey pubKey = null;
SigningPublicKey signingPubKey = null;
PrivateKey privKey = null;
SigningPrivateKey signingPrivKey = null;
Object obj[] = KeyGenerator.getInstance().generatePKIKeypair();
pubKey = (PublicKey)obj[0];
privKey = (PrivateKey)obj[1];
obj = KeyGenerator.getInstance().generateSigningKeypair();
signingPubKey = (SigningPublicKey)obj[0];
signingPrivKey = (SigningPrivateKey)obj[1];
_log.debug("SigningPublicKey: " + signingPubKey);
_log.debug("SigningPrivateKey: " + signingPrivKey);
RouterIdentity ident = new RouterIdentity();
ident.setCertificate(new Certificate(Certificate.CERTIFICATE_TYPE_NULL, null));
ident.setPublicKey(pubKey);
ident.setSigningPublicKey(signingPubKey);
info.setIdentity(ident);
Properties options = new Properties();
for (int i = 0; i < 16; i++) {
options.setProperty("option." + i, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890$:." + i);
}
options.setProperty("netConnectionSpeed", "OC12");
info.setOptions(options);
HashSet<Hash> peers = new HashSet<Hash>();
structure = (new HashTest()).createDataStructure();
peers.add((Hash) structure);
info.setPeers(peers);
info.setPublished(System.currentTimeMillis());
//info.setVersion(69);
info.sign(signingPrivKey);
return info;
}
public DataStructure createStructureToRead() { return new RouterInfo(); }
}