Package org.gudy.azureus2.core3.util

Examples of org.gudy.azureus2.core3.util.SHA1


      null_values = null;
    }
  }
 
  public void clearUsedMessagesMap(int initialCapacity) {
    used_messages = new LightHashMap(initialCapacity);
    if (null_values != null) {
      null_values = new ArrayList(0);
    }
  }
View Full Code Here


  public static void runTests() {
    try {
   
      //SHA1 sha1Jmule = new SHA1();
      MessageDigest sha1Sun = MessageDigest.getInstance("SHA-1");
      SHA1 sha1Gudy = new SHA1();
      //SHA1Az shaGudyResume = new SHA1Az();
   
      ByteBuffer buffer = ByteBuffer.allocate( 1024 * 1024 );
   
      File dir = new File( dirname );
      File[] files = dir.listFiles();

      for (int i=0; i < files.length; i++) {
        FileChannel fc = new RandomAccessFile( files[i], "r" ).getChannel();
       
        System.out.println("Testing " + files[i].getName() + " ...");
       
        while( fc.position() < fc.size() ) {
         fc.read( buffer );
         buffer.flip();
        
         byte[] raw = new byte[ buffer.limit() ];
         System.arraycopy( buffer.array(), 0, raw, 0, raw.length );

         sha1Gudy.update( buffer );
         sha1Gudy.saveState();
         ByteBuffer bb = ByteBuffer.wrap( new byte[56081] );
         sha1Gudy.digest( bb );
         sha1Gudy.restoreState();
        
         sha1Sun.update( raw );
        
         buffer.clear();
        }
       
        byte[] sun = sha1Sun.digest();
        sha1Sun.reset();
       
        byte[] gudy = sha1Gudy.digest();
        sha1Gudy.reset();
       
        if ( Arrays.equals( sun, gudy ) ) {
          System.out.println("  SHA1-Gudy: OK");
        }
        else {
View Full Code Here

  {
   
    Random rnd = new Random();

    SHA1Old oldsha = new SHA1Old();
    SHA1 newsha = new SHA1();

    ByteBuffer dBuffer = ByteBuffer.allocateDirect(BUFF_MAX_SIZE);
    ByteBuffer hBuffer = ByteBuffer.allocate(BUFF_MAX_SIZE);

    for (int i = 0; i < BUFF_MAX_SIZE; i++)
    {
      byte b = (byte) (rnd.nextInt()&0xFF);
      dBuffer.put(b);
    }
   
    dBuffer.rewind();
    hBuffer.put(dBuffer);
    hBuffer.rewind();
    dBuffer.rewind();
   

    // allow time for setting thread to high-priority
    try
    {
      System.out.println("Setting high thread priority to decrease test jitter");
      Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
      Thread.sleep(2000);
    } catch (Exception ignore)
    {
    }

    for (int t = 0; t < TESTS.length; t++)
    {

      int buffsize = TESTS[t] * 1024;

      dBuffer.position(0);
      dBuffer.limit(buffsize);
      hBuffer.position(0);
      hBuffer.limit(buffsize);

     
      int loops = LOOPS[t]/TEST_SPEED_FACTOR;

      String info = " [" + buffsize / 1024 + "KB, " + loops + "x] = ";

      double totalMBytes = ((double) buffsize / (1024 * 1024)) * loops;

     
      long time;
      double speed;

     
      System.out.println("direct:");
     
      System.out.print("Old SHA1");
      time = System.currentTimeMillis();
      for (int i = 0; i < loops; i++)
      {
        oldsha.reset();
        oldsha.digest(dBuffer);
      }
      time = System.currentTimeMillis() - time;
      speed = totalMBytes / (time / (double)1024);
      System.out.println(info + time + " ms @ " + speed + " MiB/s");

     
      System.out.print("New SHA1 ");
      time = System.currentTimeMillis();
      for (int i = 0; i < loops; i++)
      {
        newsha.reset();
        newsha.digest(dBuffer);
      }
      time = System.currentTimeMillis() - time;
      speed = totalMBytes / (time / (double)1024);
      System.out.println(info + time + " ms @ " + speed + " MiB/s");

      System.out.println("heap:");
     
      System.out.print("Old SHA1");
      time = System.currentTimeMillis();
      for (int i = 0; i < loops; i++)
      {
        oldsha.reset();
        oldsha.digest(hBuffer);
      }
      time = System.currentTimeMillis() - time;
      speed = totalMBytes / (time / (double)1024);
      System.out.println(info + time + " ms @ " + speed + " MiB/s");

     
      System.out.print("New SHA1 ");
      time = System.currentTimeMillis();
      for (int i = 0; i < loops; i++)
      {
        newsha.reset();
        newsha.digest(hBuffer);
      }
      time = System.currentTimeMillis() - time;
      speed = totalMBytes / (time / (double)1024);
      System.out.println(info + time + " ms @ " + speed + " MiB/s");

      System.out.println();
    }
   
   
    System.out.println("performing randomized buffer windowing checks, this may take a while");
   
    byte[] oldd;
    byte[] newd;
    byte[] oldh;
    byte[] newh;
   
    int size;
    int offset;
   
    ByteBuffer dview;
    ByteBuffer hview;
   
    for(int i=0;i<LOOPS[1]/TEST_SPEED_FACTOR;i++)
    {
      size = rnd.nextInt(BUFF_MAX_SIZE);
      offset = rnd.nextInt(BUFF_MAX_SIZE-size-1);
     
      hBuffer.limit(offset+size);
      hBuffer.position(offset);
      dBuffer.limit(offset+size);
      dBuffer.position(offset);
     
      oldsha.reset();
      newsha.reset();
      oldh = oldsha.digest(hBuffer);
      newh = newsha.digest(hBuffer);
      oldsha.reset();
      newsha.reset();
      oldd = oldsha.digest(dBuffer);
      newd = newsha.digest(dBuffer);
     
     
      if(!Arrays.equals(oldh, newh) || !Arrays.equals(oldd, newd) || !Arrays.equals(oldd, oldh))
      {
        System.out.println("hash mismatch at offset: "+offset+" size: "+size);
        System.out.println("\t\t"+ByteFormatter.nicePrint(oldh));
        System.out.println("\t\t"+ByteFormatter.nicePrint(newh));
        System.out.println("\t\t"+ByteFormatter.nicePrint(oldd));
        System.out.println("\t\t"+ByteFormatter.nicePrint(newd));
      }
       
      if(hBuffer.limit() != offset+size || dBuffer.limit() != offset+size || hBuffer.position() != offset || dBuffer.position() != offset)
        System.out.println("buffer does not match its original state");
     
      dview = dBuffer.slice();
      hview = hBuffer.slice();
     
      oldsha.reset();
      newsha.reset();
      oldh = oldsha.digest(hview);
      newh = newsha.digest(hview);
      oldsha.reset();
      newsha.reset();
      oldd = oldsha.digest(dview);
      newd = newsha.digest(dview);
     
     
      if(!Arrays.equals(oldh, newh) || !Arrays.equals(oldd, newd) || !Arrays.equals(oldd, oldh))
      {
        System.out.println("(view) hash mismatch at offset: "+offset+" size: "+size);
View Full Code Here

      String persist_pw_key_type  = CryptoManager.CRYPTO_CONFIG_PREFIX + "pw." + handler + ".persist_type";
 
      byte[]  salt    = getPasswordSalt();
      byte[]  pw_bytes  = new String( pw_chars ).getBytes( "UTF8" );
     
      SHA1 sha1 = new SHA1();
     
      sha1.update( ByteBuffer.wrap( salt ));
      sha1.update( ByteBuffer.wrap( pw_bytes ));
     
      String  encoded_pw = ByteFormatter.encodeString( sha1.digest());

      COConfigurationManager.setParameter( persist_timeout_key, timeout );
      COConfigurationManager.setParameter( persist_pw_key_type, pw_type );
      COConfigurationManager.setParameter( persist_pw_key, encoded_pw );
View Full Code Here

            // transform password so we can persist if needed
         
          byte[]  salt    = getPasswordSalt();
          byte[]  pw_bytes  = new String( pw_chars ).getBytes( "UTF8" );
         
          SHA1 sha1 = new SHA1();
         
          sha1.update( ByteBuffer.wrap( salt ));
          sha1.update( ByteBuffer.wrap( pw_bytes ));
         
          String  encoded_pw = ByteFormatter.encodeString( sha1.digest());
         
          if ( tester != null && !tester.testPassword( encoded_pw.toCharArray())){
         
              // retry
           
View Full Code Here

     
      if ( t != null ){
       
        byte[]  hash = t.getHash();
       
        SHA1  sha1 = new SHA1();
     
        sha1.update( ByteBuffer.wrap( IV ));
        sha1.update( ByteBuffer.wrap( hash ));
       
        id = new HashWrapper( sha1.digest() );
      }
    }
View Full Code Here

        else if( type.equalsIgnoreCase("string") ) {
          COConfigurationManager.setParameter( internal_name, setto );
          success = true;
        }
        else if( type.equalsIgnoreCase("password") ) {
          SHA1Hasher hasher = new SHA1Hasher();
         
          byte[] password = setto.getBytes();
         
          byte[] encoded;
         
          if(password.length > 0){
           
            encoded = hasher.calculateHash(password);
           
          }else{
           
            encoded = password;
          }
View Full Code Here

      lblX.setImage(img);
    }


    filterDelayTimer = new Timer("Filter");
    filterDelayTimer.addEvent(SystemTime.getCurrentTime() + 300,
        new TimerEventPerformer() {
          public void perform(TimerEvent event) {
            filterDelayTimer.destroy();
            filterDelayTimer = null;
View Full Code Here

      if ( compact_timer == null && System.getProperty("transitory.startup", "0").equals("0")){
               
        compact_timer = SimpleTimer.addPeriodicEvent(
          "IRB:compactor",
          60*1000,
          new TimerEventPerformer()
          {
            public void
            perform(
              TimerEvent event )
            { 
View Full Code Here

          }
         
          System.setProperty( "java.protocol.handler.pkgs", handlers );
          */
       
        URL.setURLStreamHandlerFactory(new AzURLStreamHandlerFactory());
            
            // DNS cache timeouts
         
          System.setProperty("sun.net.inetaddr.ttl", "60");
          System.setProperty("networkaddress.cache.ttl", "60");
View Full Code Here

TOP

Related Classes of org.gudy.azureus2.core3.util.SHA1

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.