Changeset fa6e60d


Ignore:
Timestamp:
Feb 2, 2011 10:56:00 PM (9 years ago)
Author:
mathiasdm <mathiasdm@…>
Branches:
master
Children:
85d5a85
Parents:
051fdb2 (diff), 004d787 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge of '54d4dff4f475a95dfa8e7c7878c5e6321036b988'

and 'c8ddd603cd6b832a3d5320ada590613a7b2e5c34'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/test/net/i2p/crypto/SHA256Test.java

    r051fdb2 rfa6e60d  
    3333        }
    3434    }
    35    
    36     public void testCopyConstructor(){
    37         SHA256Digest orig = new SHA256Digest();
    38         byte[] message = "update this!".getBytes();
    39         orig.update(message, 0, message.length);
    40        
    41         SHA256Digest copy = new SHA256Digest(orig);
    42        
    43         byte[] origData = new byte[32];
    44         orig.doFinal(origData, 0);
    45         byte[] copyData = new byte[32];
    46         copy.doFinal(copyData, 0);
    47        
    48         assertTrue(DataHelper.eq(origData, copyData));
    49        
    50     }
    51    
    52     public void testCheckName(){
    53         SHA256Digest digest = new SHA256Digest();
    54         assertEquals("SHA-256", digest.getAlgorithmName());
    55     }
    56    
    57     public void testManualUpdate(){
    58         byte[] data = "deathnotronic".getBytes();
    59        
    60         SHA256Digest one = new SHA256Digest();
    61         for(int i = 0; i < data.length; i++){
    62             one.update(data[i]);
     35
     36    /**
     37     * Check if the behaviour remains the same.
     38     */
     39    public void testMultipleEquality(){
     40        byte[] data = "blahblah".getBytes();
     41
     42        Hash firstHash = SHA256Generator.getInstance().calculateHash(data);
     43
     44        for(int i=0; i<5; i++){
     45            Hash h = SHA256Generator.getInstance().calculateHash(data);
     46            assertEquals(firstHash, h);
    6347        }
    64        
    65         SHA256Digest two = new SHA256Digest();
    66         two.update(data[0]);
    67         two.update(data, 1, data.length-1);
    68        
    69         byte[] oneData = new byte[32];
    70         one.doFinal(oneData, 0);
    71         byte[] twoData = new byte[32];
    72         two.doFinal(twoData, 0);
    73        
    74         assertTrue(DataHelper.eq(oneData, twoData));
    75     }
    76    
    77     public void test14Words(){
    78         byte message[] = new byte[56];
    79         _context.random().nextBytes(message);
    80         SHA256Digest orig = new SHA256Digest();
    81         orig.update(message, 0, message.length);
    82         orig.doFinal(new byte[32], 0);
    83     }
    84    
    85     public void testSHA(){
    86         I2PAppContext ctx = I2PAppContext.getGlobalContext();
    87         byte orig[] = new byte[4096];
    88         ctx.random().nextBytes(orig);
    89         Hash old = ctx.sha().calculateHash(orig);
    90         SHA256Digest d = new SHA256Digest();
    91         d.update(orig, 0, orig.length);
    92         byte out[] = new byte[Hash.HASH_LENGTH];
    93         d.doFinal(out, 0);
    94         assertTrue(DataHelper.eq(out, old.getData()));
    9548    }
    9649       
Note: See TracChangeset for help on using the changeset viewer.