标题:有没有安全高手给解释一下,这个MemCopy代码抵抗哪些攻击,原理是什么?
取消只看楼主
diycai
Rank: 8Rank: 8
等 级:贵宾
威 望:19
帖 子:147
专家分:895
注 册:2021-5-18
结帖率:66.67%
已结贴  问题点数:20 回复次数:3 
有没有安全高手给解释一下,这个MemCopy代码抵抗哪些攻击,原理是什么?
程序代码:
#include <stdio.h>
#include <stdlib.h>

typedef unsigned char        uint8_t;
typedef unsigned short        uint16_t;
typedef unsigned int        uint32_t;

uint32_t GetRandom( uint32_t* x)
{
    uint32_t ret;
    
    ret = rand();
    *x = ~ret;

    return ret;
}

void MemCopy( uint8_t* pSrc, uint8_t* pDst, uint16_t len )
{
    uint32_t i, loop_i;
    uint32_t startIndex;
    uint32_t and_mask, xor_mask;
    uint32_t randVal, invRand;

    startIndex = GetRandom( &invRand ) >> 1;
    xor_mask = GetRandom( &invRand );
    and_mask = 0x1ffff;
    
    while( ( len <= (and_mask >> 1 ) + 1 ) && ( and_mask > 1 ) )
    {
        and_mask = and_mask >> 1;
    }

    xor_mask &= and_mask;

    for( loop_i = 0; loop_i <= and_mask; loop_i++ )
    {
        i = ( startIndex + (loop_i ^ xor_mask) ) % len;
        pDst[i] = (uint8_t) GetRandom( &invRand );
        randVal = GetRandom(&invRand);
        randVal = pSrc[i];
        pDst[i] = randVal;
        randVal = invRand;
    }

    return;
}

void main()
{
    unsigned char a1[256] = {1, 2, 3, 4, 5};
    unsigned char a2[256];
    int i;

    MemCopy(a1, a2, 5);

    for (i=0; i<5; i++)
    {
        printf("%02x ", a2[i]);
    }
    printf("\n");
}
搜索更多相关主题的帖子: unsigned typedef char ret 安全 
2021-09-17 13:19
diycai
Rank: 8Rank: 8
等 级:贵宾
威 望:19
帖 子:147
专家分:895
注 册:2021-5-18
得分:0 
回复 2楼 自由而无用
The MemCopy is not supported overlap, Memory referenced by pSrc must not overlap with memory referenced by pDst.
The question is how it protect a software against Side Channel Attacks.
2021-09-18 14:20
diycai
Rank: 8Rank: 8
等 级:贵宾
威 望:19
帖 子:147
专家分:895
注 册:2021-5-18
得分:0 
回复 5楼 自由而无用
Thanks
Please help analyze this branchless function
uint32_t max( uint32_t a, uint32_t b )
{
    uint32_t mask;
    mask = b ^ (a - b);
    mask = (~mask & b) | (mask & (~a));
    mask = (mask >> 31) - 1;
    return (mask & a) | (~mask & b);
}
2021-09-18 15:26
diycai
Rank: 8Rank: 8
等 级:贵宾
威 望:19
帖 子:147
专家分:895
注 册:2021-5-18
得分:0 
回复 10楼 自由而无用

请教高人分析了这个代码,终于解惑,谢谢。
2021-09-23 11:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-506891-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018004 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved