Ejemplo n.º 1
0
 private static void ValidaCambiaSerie(ContadorCTR CTR, long serie)
 {
     Console.WriteLine();
     Console.WriteLine("mensaje:");
     CTR.CambiaSerie(serie);
     Imprime(CTR);
     for (int i = 1; i < 4; ++i)
     {
         CTR.IncrementaBloque();
         Imprime(CTR);
     }
 }
Ejemplo n.º 2
0
 private static void ValidaAnulaMensaje(ContadorCTR CTR)
 {
     Console.WriteLine();
     Console.WriteLine("mensaje:");
     CTR.AnulaMensaje();
     Imprime(CTR);
     for (int i = 1; i < 4; ++i)
     {
         CTR.IncrementaBloque();
         Imprime(CTR);
     }
 }
Ejemplo n.º 3
0
        private static void Imprime(ContadorCTR CTR)
        {
            Console.Write("    ");
            Buzon contador = new Buzon();

            contador.Reserva(ContadorCTR.BytesContador);
            CTR.AsignaContador(contador);
            for (int i = 0; i < ContadorCTR.BytesContador; ++i)
            {
                Console.Write("{0:X2}", contador [i]);
            }
            Console.WriteLine();
        }
Ejemplo n.º 4
0
 internal void Desactiva()
 {
     clave_privada = null;
     clave_publica = null;
     //if (protocolo.Longitud > 0) {
     //    protocolo.Libera ();
     //}
     seguridad_servidor  = null;
     contador_CTR_local  = null;
     contador_CTR_remoto = null;
     mensaje_general     = null;
     activa = false;
 }
Ejemplo n.º 5
0
 internal void ActivaDeServicio(Seguridad seguridad_servidor_)
 {
     activa      = true;
     de_servicio = true;
     //
     this.seguridad_servidor = seguridad_servidor_;
     //
     contador_CTR_local  = new ContadorCTR();
     contador_CTR_remoto = new ContadorCTR();
     contador_CTR_local.Inicia();
     contador_CTR_remoto.Inicia();
     //
     mensaje_general = new MensajeGeneral(this);
 }
Ejemplo n.º 6
0
 internal void ActivaDeCliente(byte [] clave_publica_)
 {
     activa     = true;
     de_cliente = true;
     //
     this.clave_publica = new Buzon();
     this.clave_publica.ReservaYCopia(clave_publica_);
     //
     contador_CTR_local  = new ContadorCTR();
     contador_CTR_remoto = new ContadorCTR();
     contador_CTR_local.Inicia();
     contador_CTR_remoto.Inicia();
     //
     mensaje_general = new MensajeGeneral(this);
 }
Ejemplo n.º 7
0
        /*
         *
         * las llamadas a los métodos solo pueden producirse en cierto orden:
         *
         *  método                  serie     mensaje     bloques
         *  --------------------------------------------------------------
         *  IniciaSerie:
         *                          0         0           0, 1, 2, ···
         *  CambiaSerie:
         *                          b1        1           0, 1, 2, ···
         *  IncrementaMensaje:
         *                          b1        2           0, 1, 2, ···
         *  IncrementaMensaje:
         *                          b1        3           0, 1, 2, ···
         *
         *      · · · · · · · · · ·
         *
         *  IncrementaMensaje:
         *                          b1        36          0, 1, 2, ···
         *  AnulaMensaje:
         *                          b1        0           0, 1, 2, ···
         *  CambiaSerie:
         *                          b2        1           0, 1, 2, ···
         *  IncrementaMensaje:
         *                          b2        2           0, 1, 2, ···
         *  IncrementaMensaje:
         *                          b2        3           0, 1, 2, ···
         *
         *      · · · · · · · · · ·
         *
         *  IncrementaMensaje:
         *                          b2        máximo      0, 1, 2, ···
         *  IncrementaMensaje:
         *                          b2        0           0, 1, 2, ···
         *  CambiaSerie:
         *                          b3        1           0, 1, 2, ···
         *  IncrementaMensaje:
         *                          b3        2           0, 1, 2, ···
         *  IncrementaMensaje:
         *                          b3        3           0, 1, 2, ···
         *
         *      · · · · · · · · · ·
         *
         */


        // ATENCIÓN:
        //      para que funcione esta prueba hay que poner:
        //      internal const int MaximoMensaje = 5;//int.MaxValue;
        private static void Valida()
        {
            ContadorCTR CTR = new ContadorCTR();

            ValidaIniciaSerie(CTR);
            ValidaCambiaSerie(CTR, 0x1F2F3F4F5F6F7F8F);
            ValidaIncrementeMensaje(CTR);
            ValidaIncrementeMensaje(CTR);
            ValidaAnulaMensaje(CTR);
            ValidaCambiaSerie(CTR, 0x7E8E9EAEBECEDEEE);
            ValidaIncrementeMensaje(CTR);
            ValidaIncrementeMensaje(CTR);
            ValidaIncrementeMensaje(CTR);
            ValidaIncrementeMensaje(CTR);
            ValidaIncrementeMensaje(CTR);
            ValidaCambiaSerie(CTR, 0x1122334455667788);
            ValidaIncrementeMensaje(CTR);
            ValidaIncrementeMensaje(CTR);
            Console.ReadLine();
        }
Ejemplo n.º 8
0
        private void Cifra_AES(CifradoAES cifra_AES, ContadorCTR cuenta_CTR)
        {
            int posicion = 0;
            int longitud = buzon_cifrado.Longitud;

            ////
            while (true)
            {
                cuenta_CTR.AsignaContador(buzon_contador);
                cifra_AES.Cifra(buzon_contador);
                //
                int resto;
                if (CifradoAES.BytesBloque <= longitud)
                {
                    resto = CifradoAES.BytesBloque;
                }
                else
                {
                    resto = longitud;
                }
                //
                for (int i = 0; i < resto; ++i)
                {
                    buzon_cifrado [posicion] ^= buzon_contador [i];
                    posicion++;
                    longitud--;
                }
                //
                if (longitud <= 0)
                {
                    return;
                }
                //
                cuenta_CTR.IncrementaBloque();
            }
        }