本文整理汇总了C++中ROL函数的典型用法代码示例。如果您正苦于以下问题:C++ ROL函数的具体用法?C++ ROL怎么用?C++ ROL使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ROL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MainRC6Decrypt
void
MainRC6Decrypt (HRC6 hAlgorithm, PULONG In, PULONG Out)
{
unsigned long a, b, c, d, t, u;
long r;
a = In[0];
b = In[1];
c = In[2];
d = In[3];
a -= hAlgorithm->skey[42];
c -= hAlgorithm->skey[43];
for (r = ROUND - 1; r >= 0; r--)
{
t = d;
d = c;
c = b;
b = a;
a = t;
t = (b * (b + b + 1));
t = ROL (t, 5);
u = (d * (d + d + 1));
u = ROL (u, 5);
c = ROR (c - hAlgorithm->skey[r + r + 3], t) ^ u;
a = ROR (a - hAlgorithm->skey[r + r + 2], u) ^ t;
}
b -= hAlgorithm->skey[0];
d -= hAlgorithm->skey[1];
Out[0] = a;
Out[1] = b;
Out[2] = c;
Out[3] = d;
}
示例2: MainRC6Decrypt
void __stdcall MainRC6Decrypt(
HRC6 hAlgorithm,
unsigned long* In,
unsigned long* Out
)
{
unsigned long a, b, c, d, t, u;
long r;
#ifdef _RC6_MODE_CBC
RC6_CBC_VECTOR vector;
#endif
a = In[0];
b = In[1];
c = In[2];
d = In[3];
#ifdef _RC6_MODE_CBC
vector[0] = a;
vector[1] = b;
vector[2] = c;
vector[3] = d;
#endif
a -= hAlgorithm->skey[42];
c -= hAlgorithm->skey[43];
for (r = ROUND - 1; r >= 0; r--)
{
t = d;
d = c;
c = b;
b = a;
a = t;
t = (b * (b + b + 1));
t = ROL (t, 5);
u = (d * (d + d + 1));
u = ROL (u, 5);
c = ROR (c - hAlgorithm->skey[r + r + 3], t) ^ u;
a = ROR (a - hAlgorithm->skey[r + r + 2], u) ^ t;
}
b -= hAlgorithm->skey[0];
d -= hAlgorithm->skey[1];
#ifdef _RC6_MODE_CBC
a ^= hAlgorithm->vector[0];
b ^= hAlgorithm->vector[1];
c ^= hAlgorithm->vector[2];
d ^= hAlgorithm->vector[3];
hAlgorithm->vector[0] = vector[0];
hAlgorithm->vector[1] = vector[1];
hAlgorithm->vector[2] = vector[2];
hAlgorithm->vector[3] = vector[3];
#endif
Out[0] = a;
Out[1] = b;
Out[2] = c;
Out[3] = d;
}
示例3: MainRC6Encrypt
void
MainRC6Encrypt (HRC6 hAlgorithm, PULONG In, PULONG Out)
{
unsigned long a, b, c, d, t, u;
long r;
a = In[0];
b = In[1];
c = In[2];
d = In[3];
b += hAlgorithm->skey[0];
d += hAlgorithm->skey[1];
for (r = 0; r < ROUND; r++)
{
t = (b * (b + b + 1));
t = ROL (t, 5);
u = (d * (d + d + 1));
u = ROL (u, 5);
a = ROL (a ^ t, u) + hAlgorithm->skey[r + r + 2];
c = ROL (c ^ u, t) + hAlgorithm->skey[r + r + 3];
t = a;
a = b;
b = c;
c = d;
d = t;
}
a += hAlgorithm->skey[42];
c += hAlgorithm->skey[43];
Out[0] = a;
Out[1] = b;
Out[2] = c;
Out[3] = d;
}
示例4: keySched
/* the key schedule routine */
void keySched(BYTE M[], int N, u32 **S, u32 K[40], int *k)
{
u32 Mo[4], Me[4];
int i, j;
BYTE vector[8];
u32 A, B;
*k = (N + 63) / 64;
*S = (u32*)malloc(sizeof(u32) * (*k));
for (i = 0; i < *k; i++)
{
Me[i] = BSWAP(((u32*)M)[2*i]);
Mo[i] = BSWAP(((u32*)M)[2*i+1]);
}
for (i = 0; i < *k; i++)
{
for (j = 0; j < 4; j++) vector[j] = _b(Me[i], j);
for (j = 0; j < 4; j++) vector[j+4] = _b(Mo[i], j);
(*S)[(*k)-i-1] = RSMatrixMultiply(vector);
}
for (i = 0; i < 20; i++)
{
A = h(2*i*RHO, Me, *k);
B = ROL(h(2*i*RHO + RHO, Mo, *k), 8);
K[2*i] = A+B;
K[2*i+1] = ROL(A + 2*B, 9);
}
}
示例5: pi2
static void pi2(ulong32 *p, ulong32 *k)
{
ulong32 t;
t = (p[1] + k[0]) & 0xFFFFFFFFUL;
t = (ROL(t, 1) + t - 1) & 0xFFFFFFFFUL;
t = (ROL(t, 4) ^ t) & 0xFFFFFFFFUL;
p[0] ^= t;
}
示例6: rc5_setup
int rc5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
#endif
{
unsigned long L[64], S[50], A, B, i, j, v, s, t, l;
_ARGCHK(skey != NULL);
_ARGCHK(key != NULL);
/* test parameters */
if (num_rounds == 0) {
num_rounds = rc5_desc.default_rounds;
}
if (num_rounds < 12 || num_rounds > 24) {
return CRYPT_INVALID_ROUNDS;
}
/* key must be between 64 and 1024 bits */
if (keylen < 8 || keylen > 128) {
return CRYPT_INVALID_KEYSIZE;
}
/* copy the key into the L array */
for (A = i = j = 0; i < (unsigned long)keylen; ) {
A = (A << 8) | ((unsigned long)(key[i++] & 255));
if ((i & 3) == 0) {
L[j++] = BSWAP(A);
A = 0;
}
}
if ((keylen & 3) != 0) {
A <<= (unsigned long)((8 * (4 - (keylen&3))));
L[j++] = BSWAP(A);
}
/* setup the S array */
t = (unsigned long)(2 * (num_rounds + 1));
S[0] = 0xB7E15163UL;
for (i = 1; i < t; i++) S[i] = S[i - 1] + 0x9E3779B9UL;
/* mix buffer */
s = 3 * MAX(t, j);
l = j;
for (A = B = i = j = v = 0; v < s; v++) {
A = S[i] = ROL(S[i] + A + B, 3);
B = L[j] = ROL(L[j] + A + B, (A+B));
i = (i + 1) % t;
j = (j + 1) % l;
}
/* copy to key */
for (i = 0; i < t; i++) {
skey->rc5.K[i] = S[i];
}
skey->rc5.rounds = num_rounds;
return CRYPT_OK;
}
示例7: rc6_setup
int rc6_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
#endif
{
unsigned long L[64], S[50], A, B, i, j, v, s, t, l;
_ARGCHK(key != NULL);
_ARGCHK(skey != NULL);
/* test parameters */
if (num_rounds != 0 && num_rounds != 20) {
return CRYPT_INVALID_ROUNDS;
}
/* key must be between 64 and 1024 bits */
if (keylen < 8 || keylen > 128) {
return CRYPT_INVALID_KEYSIZE;
}
/* copy the key into the L array */
for (A = i = j = 0; i < (unsigned long)keylen; ) {
A = (A << 8) | ((unsigned long)(key[i++] & 255));
if (!(i & 3)) {
L[j++] = BSWAP(A);
A = 0;
}
}
/* handle odd sized keys */
if (keylen & 3) {
A <<= (8 * (4 - (keylen&3)));
L[j++] = BSWAP(A);
}
/* setup the S array */
t = 44; /* fixed at 20 rounds */
S[0] = 0xB7E15163UL;
for (i = 1; i < t; i++)
S[i] = S[i - 1] + 0x9E3779B9UL;
/* mix buffer */
s = 3 * MAX(t, j);
l = j;
for (A = B = i = j = v = 0; v < s; v++) {
A = S[i] = ROL(S[i] + A + B, 3);
B = L[j] = ROL(L[j] + A + B, (A+B));
i = (i + 1) % t;
j = (j + 1) % l;
}
/* copy to key */
for (i = 0; i < t; i++) {
skey->rc6.K[i] = S[i];
}
return CRYPT_OK;
}
示例8: pi3
static void pi3(ulong32 *p, ulong32 *k)
{
ulong32 t;
t = p[0] + k[1];
t = (ROL(t, 2) + t + 1) & 0xFFFFFFFFUL;
t = (ROL(t, 8) ^ t) & 0xFFFFFFFFUL;
t = (t + k[2]) & 0xFFFFFFFFUL;
t = (ROL(t, 1) - t) & 0xFFFFFFFFUL;
t = ROL(t, 16) ^ (p[0] | t);
p[1] ^= t;
}
示例9: MainRC6Encrypt
void __stdcall MainRC6Encrypt(
HRC6 hAlgorithm,
unsigned long* In,
unsigned long* Out
)
{
unsigned long a, b, c, d, t, u;
long r;
a = In[0];
b = In[1];
c = In[2];
d = In[3];
#ifdef _RC6_MODE_CBC
a ^= hAlgorithm->vector[0];
b ^= hAlgorithm->vector[1];
c ^= hAlgorithm->vector[2];
d ^= hAlgorithm->vector[3];
#endif
b += hAlgorithm->skey[0];
d += hAlgorithm->skey[1];
for (r = 0; r < ROUND; r++)
{
t = (b * (b + b + 1));
t = ROL (t, 5);
u = (d * (d + d + 1));
u = ROL (u, 5);
a = ROL (a ^ t, u) + hAlgorithm->skey[r + r + 2];
c = ROL (c ^ u, t) + hAlgorithm->skey[r + r + 3];
t = a;
a = b;
b = c;
c = d;
d = t;
}
a += hAlgorithm->skey[42];
c += hAlgorithm->skey[43];
Out[0] = a;
Out[1] = b;
Out[2] = c;
Out[3] = d;
#ifdef _RC6_MODE_CBC
hAlgorithm->vector[0] = a;
hAlgorithm->vector[1] = b;
hAlgorithm->vector[2] = c;
hAlgorithm->vector[3] = d;
#endif
}
示例10: RC6KeySetup
void __stdcall RC6KeySetup (
HRC6 hAlgorithm,
unsigned char * key
)
{
unsigned long L[64], S[50], A, B, i, j, v, s, t, l;
/* copy the key into the L array */
for (A = i = j = 0; i < RC6_KEY_CHARS;)
{
A = (A << 8) | ((unsigned long) (key[i++] & 255));
if (!(i & 3))
{
L[j++] = BSWAP (A);
A = 0;
}
}
/* setup the S array */
t = ROUNDKEYS; /* fixed at 20 rounds */
S[0] = 0xB7E15163UL;
for (i = 1; i < t; i++)
S[i] = S[i - 1] + 0x9E3779B9UL;
/* mix buffer */
s = 3 * MAX (t, j);
l = j;
for (A = B = i = j = v = 0; v < s; v++)
{
A = S[i] = ROL (S[i] + A + B, 3);
B = L[j] = ROL (L[j] + A + B, (A + B));
i = (i + 1) % t;
j = (j + 1) % l;
}
/* copy to key */
for (i = 0; i < t; i++)
{
hAlgorithm->skey[i] = S[i];
}
#ifdef _RC6_MODE_CBC
hAlgorithm->vector[0] = 0;
hAlgorithm->vector[1] = 0;
hAlgorithm->vector[2] = 0;
hAlgorithm->vector[3] = 0;
#endif
}
示例11: FI
INLINE static ulong32 FI(ulong32 R, ulong32 Km, ulong32 Kr)
{
ulong32 I;
I = (Km + R);
I = ROL(I, Kr);
return ((S1[byte(I, 3)] ^ S2[byte(I,2)]) - S3[byte(I,1)]) + S4[byte(I,0)];
}
示例12: FIII
INLINE static ulong32 FIII(ulong32 R, ulong32 Km, ulong32 Kr)
{
ulong32 I;
I = (Km - R);
I = ROL(I, Kr);
return ((S1[byte(I, 3)] + S2[byte(I,2)]) ^ S3[byte(I,1)]) - S4[byte(I,0)];
}
示例13: pi4
static void pi4(ulong32 *p, ulong32 *k)
{
ulong32 t;
t = (p[1] + k[3]) & 0xFFFFFFFFUL;
t = (ROL(t, 2) + t + 1) & 0xFFFFFFFFUL;
p[0] ^= t;
}
示例14: Apu3B
void Apu3B()
{
// ROL dp+X
uint8_t Work8 = S9xAPUGetByteZ(OP1 + IAPU.Registers.X);
ROL(Work8);
S9xAPUSetByteZ(Work8, OP1 + IAPU.Registers.X);
IAPU.PC += 2;
}
示例15: Apu2B
void Apu2B()
{
// ROL dp
uint8_t Work8 = S9xAPUGetByteZ(OP1);
ROL(Work8);
S9xAPUSetByteZ(Work8, OP1);
IAPU.PC += 2;
}