Package com.atolsystems.atolutilities

Examples of com.atolsystems.atolutilities.ProgrammingChunk


    abstract public void addressScrambling(boolean encrypt, List<ProgrammingChunk> image);
    abstract public ProgrammingChunk processChunk(boolean encrypt, ProgrammingChunk chunk, byte []key);

    private void dataScrambling(boolean encrypt, List<ProgrammingChunk> image, List<MemRange> dataKeysMap){
        for(int i=0;i<image.size();i++){
            ProgrammingChunk chunk=image.get(i);
            MemRange range=MemRange.address2MemRange(dataKeysMap,chunk.getAddress());
            if(null!=range){
                byte []key=range.key;
                image.remove(i);
                image.add(i,processChunk(encrypt, chunk, key));
            }
View Full Code Here


        address=template.get(chunkNumber).getAddress()+offset;
        data=new byte[remaining];
    }

    protected void nextChunk(){
        template.set(chunkNumber, new ProgrammingChunk(address, data));
        chunkNumber++;
        if(template.size()>chunkNumber)
            startChunk();
        else
            data=null;
View Full Code Here

        address=template.get(chunkNumber).getAddress()+offset;
        data=new byte[remaining];
    }

    protected void nextChunk(){
        template.set(chunkNumber, new ProgrammingChunk(address, data));
        chunkNumber++;
        if(template.size()>chunkNumber)
            startChunk();
        else
            data=null;
View Full Code Here

            }
            ps.println();
            ps.println("WARNING: image contain non contiguous data, only first chunk will be evaluated.");
            ps.println();
        }
        ProgrammingChunk chunk=image.get(0);
        //store each element in a int
        int []elems=new int[n];
        {//scope
            int j = 0;
            for(int i=0;i<n*storageSize;i+=storageSize){
                int e=chunk.getData()[i];
                if(1<storageSize){
                    e=e<<8;
                    e=e+chunk.getData()[i+1];
                }
                if(2<storageSize){
                    e=e<<8;
                    e=e+chunk.getData()[i+2];
                }
                if(3<storageSize){
                    e=e<<8;
                    e=e+chunk.getData()[i+3];
                }
                elems[j++]=e;
            }
        }
        ps.println("Processing sbox:");
View Full Code Here

        //no address scrambling
    }

    @Override
    public ProgrammingChunk processChunk(boolean encrypt, ProgrammingChunk chunk, byte[] key) {
        ProgrammingChunk out;
        byte[] dataIn = chunk.getData();
        byte[] dataOut = new byte[dataIn.length];

        if (0 != (dataIn.length % 16)) {
            throw new RuntimeException("Unsupported data length: dataIn.length%16");
        }
        switch (key.length) {
            case 8:
            case 16:
            //case 24:
            //case 32:
                break;
            default:
                throw new RuntimeException("Unsupported key length: key must be 8, 16 bytes long");
        }
        try {

            for (int i = 0; i < dataIn.length; i += 16) {
                long address = chunk.getAddress() + i;
                byte[] iv = new byte[16];
                iv[0] = (byte) (0xFF & (address >> 16));
                iv[1] = (byte) (0xFF & (address >> 8));
                iv[2] = (byte) (0xFF & address);
                iv[3] = (byte) (0xFF & (address >> 16));
                iv[4] = (byte) (0xFF & (address >> 8));
                iv[5] = (byte) (0xFF & address);
                iv[6] = (byte) (0xFF & (address >> 8));
                iv[7] = (byte) (0xFF & address);

                byte[] key16=new byte[16];
                System.arraycopy(key, 0, key16, 0, key.length);
                byte[] keyMsb=AArrayUtilities.xor(key16, 8, iv, 0, 8);
                System.arraycopy(keyMsb, 0, key16, 8, 8);
                //compute the session key
                SecretKeySpec skeySpec = new SecretKeySpec(key16, "AES");
                //IvParameterSpec ivSpec = new IvParameterSpec(iv);
                // Instantiate the cipher
                Cipher cipher;
                cipher = Cipher.getInstance("AES/ECB/NoPadding");
                if (encrypt) {
                    cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
                } else {
                    cipher.init(Cipher.DECRYPT_MODE, skeySpec);
                }
                byte[] temp = cipher.doFinal(dataIn);
                System.arraycopy(temp, 0, dataOut, i, 16);
            }
        } /*catch (InvalidAlgorithmParameterException ex) {
            Logger.getLogger(AesMemCodec2.class.getName()).log(Level.SEVERE, null, ex);
        }*/ catch (IllegalBlockSizeException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        } catch (BadPaddingException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchPaddingException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidKeyException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        }

        out = new ProgrammingChunk(chunk.getAddress(), dataOut);
        return out;
    }
View Full Code Here

    @Override
    public void addressScrambling(boolean encrypt, List<ProgrammingChunk> image){
        List<ProgrammingChunk> temp=new ArrayList<ProgrammingChunk>();
        //mod 64 address scrambling by simple xor
        for(int i=0;i<image.size();i++){
            ProgrammingChunk chunk=image.get(i);
            MemRange range=MemRange.address2MemRange(addressKeysMap,chunk.getAddress());
            if(null!=range){
                byte []key=range.key;
                int first=temp.size();
                long baseAddress=chunk.getAddress();
                for(int iByte=0;iByte<chunk.getSize();iByte++){
                    long address=(baseAddress+iByte);
                    address=address^(0x3E & key[(int)(address%key.length)]);
                    byte []data=new byte[1];
                    data[0]=chunk.getData(iByte);
                    temp.add(new ProgrammingChunk(address, data));
                }
                ProgrammingChunk.pack(temp,first, first+chunk.getSize()-1);//to limit the number of chunks in the list
            }else
                temp.add(chunk);
        }
        ProgrammingChunk.pack(temp);
        image.clear();
View Full Code Here

        image.clear();
        image.addAll(temp);
    }
    @Override
    public ProgrammingChunk processChunk(boolean encrypt, ProgrammingChunk chunk, byte []key){
        ProgrammingChunk out;
        byte [] dataIn=chunk.getData();
        byte [] dataOut=new byte[dataIn.length];
        long address=chunk.getAddress();
        int keyOffset=(int)(address % key.length);
        for(int i=0;i<dataOut.length;i++){
            byte toXor=key[keyOffset];
            keyOffset++;
            keyOffset=keyOffset % key.length;
            /*if(((address+i)%512)>255)
                dataOut[i]=(byte) AES_sbox_inv[(0xFF & (dataIn[i] ^ toXor))];
            else*/
                dataOut[i]=(byte) ((byte) AES_sbox[(0xFF & (dataIn[i] ^ toXor))] ^ dataIn[i]);
        }
        out=new ProgrammingChunk(chunk.getAddress(),dataOut);
        return out;
    }
View Full Code Here

        //no address scrambling
    }

    @Override
    public ProgrammingChunk processChunk(boolean encrypt, ProgrammingChunk chunk, byte[] key) {
        ProgrammingChunk out;
        byte[] dataIn = chunk.getData();
        byte[] dataOut = new byte[dataIn.length];

        if (0 != (dataIn.length % 16)) {
            throw new RuntimeException("Unsupported data length: dataIn.length%16");
        }
        switch (key.length) {
            case 16:
            case 24:
            case 32:
                break;
            default:
                throw new RuntimeException("Unsupported key length: key must be 16, 24 or 32 bytes long");
        }
        try {

            for (int i = 0; i < dataIn.length; i += 16) {
                long address = chunk.getAddress() + i;
                byte[] iv = new byte[16];
                iv[0] = (byte) (0xFF & (address >> 16));
                iv[1] = (byte) (0xFF & (address >> 8));
                iv[2] = (byte) (0xFF & address);
                iv[3] = (byte) (0xFF & (address >> 16));
                iv[4] = (byte) (0xFF & (address >> 8));
                iv[5] = (byte) (0xFF & address);
                iv[6] = (byte) (0xFF & (address >> 8));
                iv[7] = (byte) (0xFF & address);
                //compute the session key
                SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
                IvParameterSpec ivSpec = new IvParameterSpec(iv);
                // Instantiate the cipher
                Cipher cipher;
                cipher = Cipher.getInstance("AES/CBC/NoPadding");
                if (encrypt) {
                    cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivSpec);
                } else {
                    cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivSpec);
                }
                byte[] temp = cipher.doFinal(dataIn);
                System.arraycopy(temp, 0, dataOut, i, 16);
            }
        } catch (InvalidAlgorithmParameterException ex) {
            Logger.getLogger(AesMemCodec.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalBlockSizeException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        } catch (BadPaddingException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchPaddingException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidKeyException ex) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        }

        out = new ProgrammingChunk(chunk.getAddress(), dataOut);
        return out;
    }
View Full Code Here

TOP

Related Classes of com.atolsystems.atolutilities.ProgrammingChunk

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.