decrypt: function()

in src/aes.js [435:509]


        decrypt: function(buff) {
            var st = [],
                bytes,fell_off, j;

            // Supported modes of operation
            fell_off = 0;
            switch (this.mode) {
                case AES.ECB:
                    this.ecb_decrypt(buff);
                    return 0;

                case AES.CBC:
                    for (j = 0; j < 16; j++) {
                        st[j] = this.f[j];
                        this.f[j] = buff[j];
                    }
                    this.ecb_decrypt(buff);
                    for (j = 0; j < 16; j++) {
                        buff[j] ^= st[j];
                        st[j] = 0;
                    }
                    return 0;

                case AES.CFB1:
                case AES.CFB2:
                case AES.CFB4:
                    bytes = this.mode - AES.CFB1 + 1;
                    for (j = 0; j < bytes; j++) {
                        fell_off = (fell_off << 8) | this.f[j];
                    }
                    for (j = 0; j < 16; j++) {
                        st[j] = this.f[j];
                    }
                    for (j = bytes; j < 16; j++) {
                        this.f[j - bytes] = this.f[j];
                    }
                    this.ecb_encrypt(st);
                    for (j = 0; j < bytes; j++) {
                        this.f[16 - bytes + j] = buff[j];
                        buff[j] ^= st[j];
                    }
                    return fell_off;

                case AES.OFB1:
                case AES.OFB2:
                case AES.OFB4:
                case AES.OFB8:
                case AES.OFB16:
                    bytes = this.mode - AES.OFB1 + 1;
                    this.ecb_encrypt(this.f);
                    for (j = 0; j < bytes; j++) {
                        buff[j] ^= this.f[j];
                    }
                    return 0;

                case AES.CTR1:
                case AES.CTR2:
                case AES.CTR4:
                case AES.CTR8:
                case AES.CTR16:
                    bytes = this.mode - AES.CTR1 + 1;
                    for (j = 0; j < 16; j++) {
                        st[j] = this.f[j];
                    }
                    this.ecb_encrypt(st);
                    for (j = 0; j < bytes; j++) {
                        buff[j] ^= st[j];
                    }
                    this.increment();
                    return 0;

                default:
                    return 0;
            }
        },