(byte[] blockBuffer, int block, int contentID,byte[] h3_hashes)
| 117 | } |
| 118 | |
| 119 | public byte[] decryptFileChunkHash(byte[] blockBuffer, int block, int contentID,byte[] h3_hashes){ |
| 120 | IV = ByteBuffer.allocate(16).putShort((short) contentID).array(); |
| 121 | |
| 122 | byte[] hashes = decryptFileChunk(blockBuffer,0x0400,IV); |
| 123 | |
| 124 | hashes[1] ^= (byte)contentID; |
| 125 | |
| 126 | //System.out.println("block : " + String.format("%04d", block) +":" +Util.ByteArrayToString(hashes)); |
| 127 | |
| 128 | int H0_start = (block % 16) * 20; |
| 129 | int H1_start = (16 + (block / 16) % 16) * 20; |
| 130 | int H2_start = (32 + (block / 256) % 16) * 20; |
| 131 | int H3_start = ((block / 4096) % 16) * 20; |
| 132 | |
| 133 | IV = Arrays.copyOfRange(hashes,H0_start,H0_start + 16); |
| 134 | |
| 135 | byte[] output = decryptFileChunk(blockBuffer,0x400,0xFC00,IV); |
| 136 | |
| 137 | byte[] real_h0_hash = HashUtil.hashSHA1(output); |
| 138 | byte[] expected_h0_hash = Arrays.copyOfRange(hashes,H0_start,H0_start + 20); |
| 139 | |
| 140 | if(!Arrays.equals(real_h0_hash,expected_h0_hash)){ |
| 141 | System.out.println("h0 checksum failed"); |
| 142 | System.out.println("real hash :" + Util.ByteArrayToString(real_h0_hash)); |
| 143 | System.out.println("expected hash:" + Util.ByteArrayToString(expected_h0_hash)); |
| 144 | System.exit(2); |
| 145 | //throw new IllegalArgumentException("h0 checksumfail"); |
| 146 | }else{ |
| 147 | //System.out.println("h0 checksum right!"); |
| 148 | } |
| 149 | |
| 150 | if ((block % 16) == 0){ |
| 151 | byte[] expected_h1_hash = Arrays.copyOfRange(hashes,H1_start,H1_start + 20); |
| 152 | byte[] real_h1_hash = HashUtil.hashSHA1(Arrays.copyOfRange(hashes,H0_start,H0_start + (16*20))); |
| 153 | |
| 154 | if(!Arrays.equals(expected_h1_hash, real_h1_hash)){ |
| 155 | System.out.println("h1 checksum failed"); |
| 156 | System.out.println("real hash :" + Util.ByteArrayToString(real_h1_hash)); |
| 157 | System.out.println("expected hash:" + Util.ByteArrayToString(expected_h1_hash)); |
| 158 | System.exit(2); |
| 159 | //throw new IllegalArgumentException("h1 checksumfail"); |
| 160 | }else{ |
| 161 | //System.out.println("h1 checksum right!"); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | if ((block % 256) == 0){ |
| 166 | byte[] expected_h2_hash = Arrays.copyOfRange(hashes,H2_start,H2_start + 20); |
| 167 | byte[] real_h2_hash = HashUtil.hashSHA1(Arrays.copyOfRange(hashes,H1_start,H1_start + (16*20))); |
| 168 | |
| 169 | if(!Arrays.equals(expected_h2_hash, real_h2_hash)){ |
| 170 | System.out.println("h2 checksum failed"); |
| 171 | System.out.println("real hash :" + Util.ByteArrayToString(real_h2_hash)); |
| 172 | System.out.println("expected hash:" + Util.ByteArrayToString(expected_h2_hash)); |
| 173 | System.exit(2); |
| 174 | //throw new IllegalArgumentException("h2 checksumfail"); |
| 175 | |
| 176 | }else{ |
no test coverage detected