Loading crypto/bn/bn_lib.c +23 −19 Original line number Original line Diff line number Diff line Loading @@ -767,26 +767,30 @@ void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords) b->neg ^= t; b->neg ^= t; /*- /*- * Idea behind BN_FLG_STATIC_DATA is actually to * BN_FLG_STATIC_DATA: indicates that data may not be written to. Intention * indicate that data may not be written to. * is actually to treat it as it's read-only data, and some (if not most) * Intention is actually to treat it as it's * of it does reside in read-only segment. In other words observation of * read-only data, and some (if not most) of it does * BN_FLG_STATIC_DATA in BN_consttime_swap should be treated as fatal * reside in read-only segment. In other words * condition. It would either cause SEGV or effectively cause data * observation of BN_FLG_STATIC_DATA in * corruption. * BN_consttime_swap should be treated as fatal * * condition. It would either cause SEGV or * BN_FLG_MALLOCED: refers to BN structure itself, and hence must be * effectively cause data corruption. * preserved. * BN_FLG_MALLOCED refers to BN structure itself, * * and hence must be preserved. Remaining flags are * BN_FLG_SECURE: must be preserved, because it determines how x->d was * BN_FLG_CONSTIME and BN_FLG_SECURE. Latter must be * allocated and hence how to free it. * preserved, because it determines how x->d was * * allocated and hence how to free it. This leaves * BN_FLG_CONSTTIME: sufficient to mask and swap * BN_FLG_CONSTTIME that one can do something about. * * To summarize it's sufficient to mask and swap * BN_FLG_FIXED_TOP: indicates that we haven't called bn_correct_top() on * BN_FLG_CONSTTIME alone. BN_FLG_STATIC_DATA should * the data, so the d array may be padded with additional 0 values (i.e. * be treated as fatal. * top could be greater than the minimal value that it could be). We should * be swapping it */ */ t = ((a->flags ^ b->flags) & BN_FLG_CONSTTIME) & condition; #define BN_CONSTTIME_SWAP_FLAGS (BN_FLG_CONSTTIME | BN_FLG_FIXED_TOP) t = ((a->flags ^ b->flags) & BN_CONSTTIME_SWAP_FLAGS) & condition; a->flags ^= t; a->flags ^= t; b->flags ^= t; b->flags ^= t; Loading Loading
crypto/bn/bn_lib.c +23 −19 Original line number Original line Diff line number Diff line Loading @@ -767,26 +767,30 @@ void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords) b->neg ^= t; b->neg ^= t; /*- /*- * Idea behind BN_FLG_STATIC_DATA is actually to * BN_FLG_STATIC_DATA: indicates that data may not be written to. Intention * indicate that data may not be written to. * is actually to treat it as it's read-only data, and some (if not most) * Intention is actually to treat it as it's * of it does reside in read-only segment. In other words observation of * read-only data, and some (if not most) of it does * BN_FLG_STATIC_DATA in BN_consttime_swap should be treated as fatal * reside in read-only segment. In other words * condition. It would either cause SEGV or effectively cause data * observation of BN_FLG_STATIC_DATA in * corruption. * BN_consttime_swap should be treated as fatal * * condition. It would either cause SEGV or * BN_FLG_MALLOCED: refers to BN structure itself, and hence must be * effectively cause data corruption. * preserved. * BN_FLG_MALLOCED refers to BN structure itself, * * and hence must be preserved. Remaining flags are * BN_FLG_SECURE: must be preserved, because it determines how x->d was * BN_FLG_CONSTIME and BN_FLG_SECURE. Latter must be * allocated and hence how to free it. * preserved, because it determines how x->d was * * allocated and hence how to free it. This leaves * BN_FLG_CONSTTIME: sufficient to mask and swap * BN_FLG_CONSTTIME that one can do something about. * * To summarize it's sufficient to mask and swap * BN_FLG_FIXED_TOP: indicates that we haven't called bn_correct_top() on * BN_FLG_CONSTTIME alone. BN_FLG_STATIC_DATA should * the data, so the d array may be padded with additional 0 values (i.e. * be treated as fatal. * top could be greater than the minimal value that it could be). We should * be swapping it */ */ t = ((a->flags ^ b->flags) & BN_FLG_CONSTTIME) & condition; #define BN_CONSTTIME_SWAP_FLAGS (BN_FLG_CONSTTIME | BN_FLG_FIXED_TOP) t = ((a->flags ^ b->flags) & BN_CONSTTIME_SWAP_FLAGS) & condition; a->flags ^= t; a->flags ^= t; b->flags ^= t; b->flags ^= t; Loading