Ejemplo n.º 1
0
 public SMFContext(SMFMode mode)
 {
     this.mode      = mode;
     this.isPadding = true;
     this.iv        = new byte[InputBlockSize];
     this.sk        = new long[32];
 }
Ejemplo n.º 2
0
        static private byte[] padding(byte[] input, SMFMode mode)
        {
            if (input == null)
            {
                return(null);
            }

            byte[] ret = (byte[])null;
            if (mode == SMFMode.SM4_ENCRYPT)
            {
                int p = 16 - input.Length % 16;
                ret = new byte[input.Length + p];
                Array.Copy(input, 0, ret, 0, input.Length);
                for (int i = 0; i < p; i++)
                {
                    ret[input.Length + i] = (byte)p;
                }
            }
            else
            {
                int p = input[input.Length - 1];
                ret = new byte[input.Length - p];
                Array.Copy(input, 0, ret, 0, input.Length - p);
            }
            return(ret);
        }