Beispiel #1
0
AES_RETURN aes_xi(decrypt_key192)(const unsigned char *key, aes_decrypt_ctx cx[1])
{   uint32_t    ss[7];
#if defined( d_vars )
        d_vars;
#endif

    cx->ks[v(48,(0))] = ss[0] = word_in(key, 0);
    cx->ks[v(48,(1))] = ss[1] = word_in(key, 1);
    cx->ks[v(48,(2))] = ss[2] = word_in(key, 2);
    cx->ks[v(48,(3))] = ss[3] = word_in(key, 3);

#ifdef DEC_KS_UNROLL
    cx->ks[v(48,(4))] = ff(ss[4] = word_in(key, 4));
    cx->ks[v(48,(5))] = ff(ss[5] = word_in(key, 5));
    kdf6(cx->ks, 0); kd6(cx->ks, 1);
    kd6(cx->ks, 2);  kd6(cx->ks, 3);
    kd6(cx->ks, 4);  kd6(cx->ks, 5);
    kd6(cx->ks, 6);  kdl6(cx->ks, 7);
#else
    cx->ks[v(48,(4))] = ss[4] = word_in(key, 4);
    cx->ks[v(48,(5))] = ss[5] = word_in(key, 5);
    {   uint32_t i;

        for(i = 0; i < 7; ++i)
            k6e(cx->ks, i);
        k6ef(cx->ks, 7);
#if !(DEC_ROUND == NO_TABLES)
        for(i = N_COLS; i < 12 * N_COLS; ++i)
            cx->ks[i] = inv_mcol(cx->ks[i]);
#endif
    }
#endif
    cx->inf.l = 0;
    cx->inf.b[0] = 12 * 16;

#ifdef USE_VIA_ACE_IF_PRESENT
    if(VIA_ACE_AVAILABLE)
        cx->inf.b[1] = 0xff;
#endif
    return EXIT_SUCCESS;
}
Beispiel #2
0
aes_rval aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1])
{   aes_32t    ss[7];
#if defined( d_vars )
        d_vars;
#endif
    cx->ks[0] = ss[0] = word_in(key, 0);
    cx->ks[1] = ss[1] = word_in(key, 1);
    cx->ks[2] = ss[2] = word_in(key, 2);
    cx->ks[3] = ss[3] = word_in(key, 3);

#if DEC_UNROLL == NONE
    cx->ks[4] = ss[4] = word_in(key, 4);
    cx->ks[5] = ss[5] = word_in(key, 5);
    {   aes_32t i;

        for(i = 0; i < (13 * N_COLS - 7) / 6; ++i)
            ke6(cx->ks, i);
        kel6(cx->ks, 7);
#if !(DEC_ROUND == NO_TABLES)
        for(i = N_COLS; i < 12 * N_COLS; ++i)
            cx->ks[i] = inv_mcol(cx->ks[i]);
#endif
    }
#else
    cx->ks[4] = ff(ss[4] = word_in(key, 4));
    cx->ks[5] = ff(ss[5] = word_in(key, 5));
    kdf6(cx->ks, 0); kd6(cx->ks, 1);
    kd6(cx->ks, 2);  kd6(cx->ks, 3);
    kd6(cx->ks, 4);  kd6(cx->ks, 5);
    kd6(cx->ks, 6); kdl6(cx->ks, 7);
#endif
    cx->rn = 12;
	#if CC_AES_USE_HARDWARE
	bcopy(key, cx->keyBytes, 24);
	cx->keyLength = 24;
	#endif
#if defined( AES_ERR_CHK )
    return aes_good;
#endif
}
aes_rval aes_decrypt_key192(const void *in_key, aes_decrypt_ctx cx[1])
{   aes_32t    ss[7];
#ifdef  d_vars
        d_vars;
#endif
    cx->ks[0] = ss[0] = word_in(in_key, 0);
    cx->ks[1] = ss[1] = word_in(in_key, 1);
    cx->ks[2] = ss[2] = word_in(in_key, 2);
    cx->ks[3] = ss[3] = word_in(in_key, 3);

#if DEC_UNROLL == NONE
    cx->ks[4] = ss[4] = word_in(in_key, 4);
    cx->ks[5] = ss[5] = word_in(in_key, 5);
    {   aes_32t i;

        for(i = 0; i < (13 * N_COLS - 1) / 6; ++i)
            ke6(cx->ks, i);
#if !(DEC_ROUND == NO_TABLES)
        for(i = N_COLS; i < 12 * N_COLS; ++i)
            cx->ks[i] = inv_mcol(cx->ks[i]);
#endif
    }
#else
    cx->ks[4] = ff(ss[4] = word_in(in_key, 4));
    cx->ks[5] = ff(ss[5] = word_in(in_key, 5));
    kdf6(cx->ks, 0); kd6(cx->ks, 1);
    kd6(cx->ks, 2);  kd6(cx->ks, 3);
    kd6(cx->ks, 4);  kd6(cx->ks, 5);
    kd6(cx->ks, 6); kdl6(cx->ks, 7);
#endif

    /* cx->ks[45] ^ cx->ks[52] ^ cx->ks[53] is zero for a 256 bit       */
    /* key and must be non-zero for 128 and 192 bits keys   */
    cx->ks[53] = cx->ks[45];
    cx->ks[52] = 12;
#ifdef AES_ERR_CHK
    return aes_good;
#endif
}
Beispiel #4
0
///===============Follow a link in the page based on the name=======================///
void Browser::follow_link(std::string name_of_link_to_follow, int usertimeout=20)
{
    if(links.size()==0)
    {
        std::cerr<<"\n[!] No links found\n";
        return;
    }
    std::string to_follow="";
    for(int i=0;i<links.size();i++)
    {
        if(links[i].name()==name_of_link_to_follow)
        {
            to_follow=links[i].url();
            break;
        }
    }
    if(to_follow=="")
    {
        std::cerr<<"\n[!] No such link in the page found\n";
        return;
    }
    //if the link is already a complete one we open it directly else we add the site root
    if(word_in(to_follow,"http://"))
    {
        open(to_follow,usertimeout);
    }
    else
    {
        std::string now_on = get_first_root();
        //here we are on the last slash
        if(to_follow[0]!='/')
        {
            open(now_on+to_follow);
        }
        else
        {
            open(now_on.substr(0,now_on.size()-1)+to_follow);
        }
    }
}
Beispiel #5
0
static void
aes_decrypt_key192(const unsigned char *key, uint32_t rk[])
{
	uint32_t	ss[7];
#if defined(d_vars)
	d_vars;
#endif
	rk[v(48, (0))] = ss[0] = word_in(key, 0);
	rk[v(48, (1))] = ss[1] = word_in(key, 1);
	rk[v(48, (2))] = ss[2] = word_in(key, 2);
	rk[v(48, (3))] = ss[3] = word_in(key, 3);

#ifdef DEC_KS_UNROLL
	ss[4] = word_in(key, 4);
	rk[v(48, (4))] = ff(ss[4]);
	ss[5] = word_in(key, 5);
	rk[v(48, (5))] = ff(ss[5]);
	kdf6(rk, 0); kd6(rk, 1);
	kd6(rk, 2);  kd6(rk, 3);
	kd6(rk, 4);  kd6(rk, 5);
	kd6(rk, 6);  kdl6(rk, 7);
#else
	rk[v(48, (4))] = ss[4] = word_in(key, 4);
	rk[v(48, (5))] = ss[5] = word_in(key, 5);
	{
		uint32_t	i;

		for (i = 0; i < 7; ++i)
			k6e(rk, i);
		k6ef(rk, 7);
#if !(DEC_ROUND == NO_TABLES)
		for (i = MAX_AES_NB; i < 12 * MAX_AES_NB; ++i)
			rk[i] = inv_mcol(rk[i]);
#endif
	}
#endif
}
Beispiel #6
0
aes_rval aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1])
{   aes_32t    ss[8];
#if defined( d_vars )
        d_vars;
#endif
    cx->ks[0] = ss[0] = word_in(key, 0);
    cx->ks[1] = ss[1] = word_in(key, 1);
    cx->ks[2] = ss[2] = word_in(key, 2);
    cx->ks[3] = ss[3] = word_in(key, 3);

#if DEC_UNROLL == NONE
    cx->ks[4] = ss[4] = word_in(key, 4);
    cx->ks[5] = ss[5] = word_in(key, 5);
    cx->ks[6] = ss[6] = word_in(key, 6);
    cx->ks[7] = ss[7] = word_in(key, 7);
    {   aes_32t i;

        for(i = 0; i < (15 * N_COLS - 9) / 8; ++i)
            ke8(cx->ks,  i);
        kel8(cx->ks,  i);
#if !(DEC_ROUND == NO_TABLES)
        for(i = N_COLS; i < 14 * N_COLS; ++i)
            cx->ks[i] = inv_mcol(cx->ks[i]);

#endif
    }
#else
    cx->ks[4] = ff(ss[4] = word_in(key, 4));
    cx->ks[5] = ff(ss[5] = word_in(key, 5));
    cx->ks[6] = ff(ss[6] = word_in(key, 6));
    cx->ks[7] = ff(ss[7] = word_in(key, 7));
    kdf8(cx->ks, 0); kd8(cx->ks, 1);
    kd8(cx->ks, 2);  kd8(cx->ks, 3);
    kd8(cx->ks, 4);  kd8(cx->ks, 5);
    kdl8(cx->ks, 6);
#endif
    cx->rn = 14;
#if defined( AES_ERR_CHK )
    return aes_good;
#endif
}
Beispiel #7
0
AES_RETURN aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1])
{   uint_32t    ss[9];
#if defined( d_vars )
        d_vars;
#endif
    cx->ks[v(56,(0))] = ss[0] = word_in(key, 0);
    cx->ks[v(56,(1))] = ss[1] = word_in(key, 1);
    cx->ks[v(56,(2))] = ss[2] = word_in(key, 2);
    cx->ks[v(56,(3))] = ss[3] = word_in(key, 3);

#ifdef DEC_KS_UNROLL
    ss[4] = word_in(key, 4);
    cx->ks[v(56,(4))] = ff(ss[4]);
    ss[4] = word_in(key, 5);
    cx->ks[v(56,(5))] = ff(ss[5]);
    ss[4] = word_in(key, 6);
    cx->ks[v(56,(6))] = ff(ss[6]);
    ss[4] = word_in(key, 7);
    cx->ks[v(56,(7))] = ff(ss[7]);
    kdf8(cx->ks, 0); kd8(cx->ks, 1);
    kd8(cx->ks, 2);  kd8(cx->ks, 3);
    kd8(cx->ks, 4);  kd8(cx->ks, 5);
    kdl8(cx->ks, 6);
#else
    cx->ks[v(56,(4))] = ss[4] = word_in(key, 4);
    cx->ks[v(56,(5))] = ss[5] = word_in(key, 5);
    cx->ks[v(56,(6))] = ss[6] = word_in(key, 6);
    cx->ks[v(56,(7))] = ss[7] = word_in(key, 7);
    {   uint_32t i;

        for(i = 0; i < 6; ++i)
            k8e(cx->ks,  i);
        k8ef(cx->ks,  6);
#if !(DEC_ROUND == NO_TABLES)
        for(i = N_COLS; i < 14 * N_COLS; ++i)
            cx->ks[i] = inv_mcol(cx->ks[i]);
#endif
    }
#endif
    cx->inf.l = 0;
    cx->inf.b[0] = 14 * 16;

#ifdef USE_VIA_ACE_IF_PRESENT
    if(VIA_ACE_AVAILABLE)
        cx->inf.b[1] = 0xff;
#endif
    return EXIT_SUCCESS;
}
Beispiel #8
0
aes_rval aes_set_decrypt_key(const unsigned char in_key[], unsigned int klen, aes_ctx cx[1])
{   aes_32t    ss[8];
    d_vars

#if !defined(FIXED_TABLES)
#ifdef GLOBALS
    if(!t_use(in,it)) gen_tabs();
#else
    if(!cx->t_ptr || !t_use(in,it)) gen_tabs(cx);
#endif
#endif

#if !defined(BLOCK_SIZE)
    if(!cx->n_blk) cx->n_blk = 16;
#else
    cx->n_blk = BLOCK_SIZE;
#endif

    if(((klen & 7) || klen < 16 || klen > 32) && ((klen & 63) || klen < 128 || klen > 256))
    {
        cx->n_rnd = 0; return aes_bad;
    }

    klen >>= (klen < 128 ? 2 : 5);
    cx->n_blk = (cx->n_blk & ~3) | 2;

    cx->k_sch[0] = ss[0] = word_in(in_key     );
    cx->k_sch[1] = ss[1] = word_in(in_key +  4);
    cx->k_sch[2] = ss[2] = word_in(in_key +  8);
    cx->k_sch[3] = ss[3] = word_in(in_key + 12);

#if (BLOCK_SIZE == 16) && (DEC_UNROLL != NONE)

    switch(klen)
    {
    case 4:
        kdf4(cx->k_sch, 0); kd4(cx->k_sch, 1);
        kd4(cx->k_sch, 2); kd4(cx->k_sch, 3);
        kd4(cx->k_sch, 4); kd4(cx->k_sch, 5);
        kd4(cx->k_sch, 6); kd4(cx->k_sch, 7);
        kd4(cx->k_sch, 8); kdl4(cx->k_sch, 9);
        cx->n_rnd = 10; break;
    case 6:
        cx->k_sch[4] = ff(ss[4] = word_in(in_key + 16));
        cx->k_sch[5] = ff(ss[5] = word_in(in_key + 20));
        kdf6(cx->k_sch, 0); kd6(cx->k_sch, 1);
        kd6(cx->k_sch, 2); kd6(cx->k_sch, 3);
        kd6(cx->k_sch, 4); kd6(cx->k_sch, 5);
        kd6(cx->k_sch, 6); kdl6(cx->k_sch, 7);
        cx->n_rnd = 12; break;
    case 8:
        cx->k_sch[4] = ff(ss[4] = word_in(in_key + 16));
        cx->k_sch[5] = ff(ss[5] = word_in(in_key + 20));
        cx->k_sch[6] = ff(ss[6] = word_in(in_key + 24));
        cx->k_sch[7] = ff(ss[7] = word_in(in_key + 28));
        kdf8(cx->k_sch, 0); kd8(cx->k_sch, 1);
        kd8(cx->k_sch, 2); kd8(cx->k_sch, 3);
        kd8(cx->k_sch, 4); kd8(cx->k_sch, 5);
        kdl8(cx->k_sch, 6);
        cx->n_rnd = 14; break;
    default:
        ;
    }
#else
    cx->n_rnd = (klen > nc ? klen : nc) + 6;
    {   aes_32t i, l;
        l = (nc * cx->n_rnd + nc - 1) / klen;

        switch(klen)
        {
        case 4:
            for(i = 0; i < l; ++i)
                ke4(cx->k_sch, i);
            break;
        case 6:
            cx->k_sch[4] = ss[4] = word_in(in_key + 16);
            cx->k_sch[5] = ss[5] = word_in(in_key + 20);
            for(i = 0; i < l; ++i)
                ke6(cx->k_sch, i);
            break;
        case 8:
            cx->k_sch[4] = ss[4] = word_in(in_key + 16);
            cx->k_sch[5] = ss[5] = word_in(in_key + 20);
            cx->k_sch[6] = ss[6] = word_in(in_key + 24);
            cx->k_sch[7] = ss[7] = word_in(in_key + 28);
            for(i = 0; i < l; ++i)
                ke8(cx->k_sch,  i);
            break;
        default:
            ;
        }
#if (DEC_ROUND != NO_TABLES)
        for(i = nc; i < nc * cx->n_rnd; ++i)
            cx->k_sch[i] = inv_mcol(cx->k_sch[i]);
#endif
    }
#endif

    return aes_good;
}
Beispiel #9
0
///===================submit the form depending on GET or POST=======================///
void Browser::submit(int timeout=30)
{
    std::string temp_url="";
    int backward_it     = 1;
    //get out of the program if we don't have a post or a get in the form
    assert(word_in(form.method_,"get")|| word_in(form.method_,"post") );

    //if the url is already complete
    if( word_in(form.url_,"http://"))
    {
        temp_url = form.url();
    }
    //otherwise we add after the root of dir
    //meaning after the first /
    //or if there's not, we add a slash and append it
    else
    {
        temp_url = geturl();
        bool https = false;
        //remove the http:// to not confuse the slashes
        replaceAll(temp_url,"http://","");
        if( word_in(temp_url,"https://") )
            https = true;
        if(https)
            replaceAll(temp_url,"https://","");

        //now test if we are in a directory
        //meaning something like:
        //www.something.com/   or
        //www.somthing.com/blah.php or
        //www.something.com/else/somthing.php
        if( word_in(temp_url,"/"))
        {
            while(temp_url[temp_url.size()-backward_it]!='/')
            {
                backward_it++;
            }
            //here we are on the last slash
            if(form.url_[0]!='/')
            {
                if(!https)
                    temp_url = "http://" + temp_url.substr(0,temp_url.size()-backward_it+1)+form.url();
                else
                    temp_url = "https://" + temp_url.substr(0,temp_url.size()-backward_it+1)+form.url();
            }
            else
            {
                if(!https)
                    temp_url = "http://" + temp_url.substr(0,temp_url.size()-backward_it)+form.url();
                else
                    temp_url = "https://" + temp_url.substr(0,temp_url.size()-backward_it)+form.url();
            }
        }
        //meaning we don't have any slash, we are in the top
        //dir , so something like:
        //www.blahblah.com
        else
        {
            //here we concatenate all we need in this way:
            //http://www.blahblah.com/formurl.php
            if(!https)
                temp_url = "http://" + temp_url + "/" + form.url();
            else
                temp_url = "https://" + temp_url + "/" + form.url();
        }
    }

    //we have the url where we will post or get set correctly
    //now prepare the get or post to do and submit
    if( word_in(form.method_,"get"))
    {
        //if it's a get
        //append ? to action then add value1=avalue&value2=anothervalue
        //then open the link and decide if it writes to a file or not depending on the write_bytes
        curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
        temp_url += "?";

        //loop through all that:
        //select   :name(), options[selected(),value()]
        //input    :name(), type(), value()
        //textarea :name(), value()
        //bytes    :strings...

        //select
        for(unsigned int ii=0;ii<form.select.size();ii++)
        {
            for(unsigned int jj=0;jj<form.select[ii].options.size();jj++)
            {
                if(form.select[ii].options[jj].value()!="" &&form.select[ii].options[jj].selected()==true)
                {
                    temp_url+=escape(form.select[ii].name());
                    temp_url+="=";
                    temp_url+=escape(form.select[ii].options[jj].value());
                    temp_url+="&";
                }
            }
        }

        //input
        for(unsigned int ii=0;ii<form.input.size();ii++)
        {
            if(form.input[ii].value()!="")
            {
                temp_url+=escape(form.input[ii].name());
                temp_url+="=";
                temp_url+=escape(form.input[ii].value());
                temp_url+="&";
            }
        }

        //textarea
        for(unsigned int ii=0;ii<form.textarea.size();ii++)
        {
            if(form.textarea[ii].value()!="")
            {
                temp_url+=escape(form.textarea[ii].name());
                temp_url+="=";
                temp_url+=escape(form.textarea[ii].value());
                temp_url+="&";
            }
        }
        //stil use open because we can have write_bytes as a callback
        open(temp_url,timeout);

    }
    //FOR POSTS NOW!
    else if( word_in(form.method_,"post") )
    {
        //if it's a post
        //we check what part of the form is pure bin

        //input -- here we can have the type FILE
        //which always imply uploading a file
        for(unsigned int ii=0;ii<form.input.size();ii++)
        {
            if(form.input[ii].value()!="")
            {

                //check if bytes and content type were specified
                for( std::map<std::string,std::string>::iterator inside_bytes=form.bytes_.begin();
                     inside_bytes!=form.bytes_.end();
                     ++inside_bytes)
                {
                    //if names of the input is inside the bytes
                    if( (*inside_bytes).first ==  form.input[ii].name() )
                    {
                        //if we didn't specified a content type
                        if( (*inside_bytes).second == "" )
                        {
                            // Fill in the file upload field
                            curl_formadd(&formpost,
                                     &lastptr,
                                     CURLFORM_COPYNAME, form.input[ii].name().c_str(),
                                     CURLFORM_FILE, form.input[ii].value().c_str(),
                                     CURLFORM_END);
                        }
                        //specified a content type
                        else
                        {
                            // Fill in the file upload field with the content type
                            curl_formadd(&formpost,
                                     &lastptr,
                                     CURLFORM_COPYNAME, form.input[ii].name().c_str(),
                                     CURLFORM_FILE, form.input[ii].value().c_str(),
                                     CURLFORM_CONTENTTYPE, (*inside_bytes).second.c_str(),
                                     CURLFORM_END);
                        }
                    }
                }
                //

                //if we have the type file then it's a file:
                if( word_in(form.input[ii].type(),"file") )
                {
                    // Fill in the file upload field
                    curl_formadd(&formpost,
                                 &lastptr,
                                 CURLFORM_COPYNAME, form.input[ii].name().c_str(),
                                 CURLFORM_FILE, form.input[ii].value().c_str(),
                                 CURLFORM_END);
                }
                //else if it's pure text
                else
                {
                    // Fill in the submit field too, even if this is rarely needed
                    curl_formadd(&formpost,
                                 &lastptr,
                                 CURLFORM_COPYNAME, form.input[ii].name().c_str(),
                                 CURLFORM_COPYCONTENTS, form.input[ii].value().c_str(),
                                 CURLFORM_END);
                }
            }
        }
        //select
        for(unsigned int ii=0;ii<form.select.size();ii++)
        {
            for(unsigned int jj=0;jj<form.select[ii].options.size();jj++)
            {
                if(form.select[ii].options[jj].value()!="" && form.select[ii].options[jj].selected()==true)
                {
                    curl_formadd(&formpost,
                                 &lastptr,
                                 CURLFORM_COPYNAME, form.select[ii].name().c_str(),
                                 CURLFORM_COPYCONTENTS, form.select[ii].options[jj].value().c_str(),
                                 CURLFORM_END);
                }
            }
        }
        //textarea
        for(unsigned int ii=0;ii<form.textarea.size();ii++)
        {
            if(form.textarea[ii].value()!="")
            {
                curl_formadd(&formpost,
                             &lastptr,
                             CURLFORM_COPYNAME, form.textarea[ii].name().c_str(),
                             CURLFORM_COPYCONTENTS, form.textarea[ii].value().c_str(),
                             CURLFORM_END);
            }
        }

        //add our prepared formpost to the options
        curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);

        //stil use open because we can have write_bytes as a callback
        open_form(temp_url,timeout);
    }

}
Beispiel #10
0
static void
aes_decrypt_key256(const unsigned char *key, uint32_t rk[])
{
	uint32_t	ss[9];
#if defined(d_vars)
	d_vars;
#endif
	rk[v(56, (0))] = ss[0] = word_in(key, 0);
	rk[v(56, (1))] = ss[1] = word_in(key, 1);
	rk[v(56, (2))] = ss[2] = word_in(key, 2);
	rk[v(56, (3))] = ss[3] = word_in(key, 3);

#ifdef DEC_KS_UNROLL
	ss[4] = word_in(key, 4);
	rk[v(56, (4))] = ff(ss[4]);
	ss[5] = word_in(key, 5);
	rk[v(56, (5))] = ff(ss[5]);
	ss[6] = word_in(key, 6);
	rk[v(56, (6))] = ff(ss[6]);
	ss[7] = word_in(key, 7);
	rk[v(56, (7))] = ff(ss[7]);
	kdf8(rk, 0); kd8(rk, 1);
	kd8(rk, 2);  kd8(rk, 3);
	kd8(rk, 4);  kd8(rk, 5);
	kdl8(rk, 6);
#else
	rk[v(56, (4))] = ss[4] = word_in(key, 4);
	rk[v(56, (5))] = ss[5] = word_in(key, 5);
	rk[v(56, (6))] = ss[6] = word_in(key, 6);
	rk[v(56, (7))] = ss[7] = word_in(key, 7);
	{
		uint32_t	i;

		for (i = 0; i < 6; ++i)
			k8e(rk,  i);
		k8ef(rk,  6);
#if !(DEC_ROUND == NO_TABLES)
		for (i = MAX_AES_NB; i < 14 * MAX_AES_NB; ++i)
			rk[i] = inv_mcol(rk[i]);
#endif
	}
#endif	/* DEC_KS_UNROLL */
}