📄 ibecacheimpl.c
字号:
/* Acquire the cache lock to syncronize access */
VOLT_SET_FNCT_LINE (fnctLine)
status = ctx->LockIBECache(ibeCacheCtx);
if (status != 0)
break;
lockAcquired = 1;
/* Run through the entry link list. If we find a match, we'll adjust
* the entry.
*/
nextEntry = cache->cacheList;
while (nextEntry != (VoltIBECacheEntry *)0)
{
entry = nextEntry;
nextEntry = (VoltIBECacheEntry *)(entry->nextEntry);
if (entry->theCtx != *theCtx)
continue;
/* The ctx matched, decrement this entry's counter and set theCtx
* to NULL.
*/
*theCtx = (Pointer)0;
if (entry->referenceCount != 0)
entry->referenceCount--;
break;
}
}
while (0);
if (lockAcquired)
{
status2 = ctx->UnlockIBECache(ibeCacheCtx);
if (status == 0)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = status2;
}
}
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, ibeCacheCtx, status, 0, 0,
(char *)0, "VoltReleaseBfCtxFromCache", fnctLine, (char *)0)
return (status);
}
int VoltGetIBECacheEntryCount (
Pointer ibeCacheCtx,
unsigned int *count
)
{
int status, status2;
int lockAcquired = 0;
unsigned int theCount;
VoltIBECacheCtx *ctx = (VoltIBECacheCtx *)ibeCacheCtx;
VoltIBELocalCache *cache = (VoltIBELocalCache *)(ctx->localCtx);
VoltIBECacheEntry *nextEntry;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
VOLT_SET_FNCT_LINE (fnctLine)
status = ctx->LockIBECache(ibeCacheCtx);
if (status != 0)
break;
lockAcquired = 1;
/* Run through the list until finding the last one. Count how many
* there are.
*/
nextEntry = cache->cacheList;
theCount = 0;
while (nextEntry != (VoltIBECacheEntry *)0)
{
nextEntry = (VoltIBECacheEntry *)(nextEntry->nextEntry);
theCount++;
}
*count = theCount;
}
while (0);
if (lockAcquired)
{
status2 = ctx->UnlockIBECache(ibeCacheCtx);
if (status == 0)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = status2;
}
}
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, ibeCacheCtx, status, 0, 0,
(char *)0, "VoltGetIBECacheEntryCount", fnctLine, (char *)0)
return (status);
}
int VoltGetIBECacheEntry (
Pointer ibeCacheCtx,
unsigned int index,
unsigned char *element,
unsigned int bufferSize,
unsigned int *elementLen
)
{
int status, status2;
int lockAcquired = 0;
unsigned int count;
VoltIBECacheCtx *ctx = (VoltIBECacheCtx *)ibeCacheCtx;
VoltIBELocalCache *cache = (VoltIBELocalCache *)(ctx->localCtx);
VoltIBECacheEntry *entry;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Acquire the cache lock to syncronize access */
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = ctx->LockIBECache(ibeCacheCtx);
if (status != 0)
break;
lockAcquired = 1;
/* Run through the list, counting the entries until the count equals
* the index.
*/
entry = cache->cacheList;
count = 0;
while (entry != (VoltIBECacheEntry *)0)
{
if (index == count)
break;
entry = (VoltIBECacheEntry *)(entry->nextEntry);
count++;
}
/* If entry is NULL, there is no entry at the requested index.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_NO_ELEMENT_AT_INDEX;
if (entry == (VoltIBECacheEntry *)0)
break;
if (entry->ctxType == VOLT_IBE_CTX_TYPE_BF)
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltBuildCacheElementBF (
ctx, cache, entry, element, bufferSize, elementLen);
}
else
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltBuildCacheElementBB (
ctx, cache, entry, element, bufferSize, elementLen);
}
} while (0);
if (lockAcquired)
{
status2 = ctx->UnlockIBECache(ibeCacheCtx);
if (status == 0)
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = status2;
}
}
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, ibeCacheCtx, status, 0, errorType,
(char *)0, "VoltGetIBECacheEntry", fnctLine, (char *)0)
return (status);
}
int VoltParseIBECacheEntry (
VoltLibCtx *libCtx,
Pointer ibeCacheCtx,
unsigned char *element,
unsigned int elementLen,
unsigned int *flag,
unsigned char **reference,
unsigned int *referenceLen
)
{
int status;
unsigned int primeLen, subprimeLen, offset;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* There must be at least 14 bytes for the leading integers (flag,
* primeLen, etc.)
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (elementLen < 14)
break;
/* The first value is the flag.
*/
*flag = GetIntegerBE (element, 2);
/* The next numbers are the primeLen, subprimeLen, and accelCount.
* We don't need the accel count.
*/
primeLen = GetIntegerBE (element + 2, 4);
subprimeLen = GetIntegerBE (element + 6, 4);
/* There should be at least a prime, subprime, baseX, baseY, pubX,
* and pubY (if BB, there are three public points, but we're
* interested in the first public point).
*/
VOLT_SET_FNCT_LINE (fnctLine)
offset = (5 * primeLen) + subprimeLen + 14;
if (elementLen < offset)
break;
/* We set offset to just beyond the pubY, move back.
*/
offset -= primeLen;
/* Skip any leading 00 bytes (not likely, but check anyway.
*/
while ( (element[offset] == 0) && (primeLen > 1) )
{
offset++;
primeLen--;
}
/* The reference is the block of coordinates after the subprime.
*/
*reference = element + 14 + primeLen + subprimeLen;
*referenceLen = 4 * primeLen;
status = 0;
} while (0);
VOLT_LOG_ERROR_INFO_COMPARE (
status, libCtx, 0, status, 0, errorType,
(char *)0, "VoltParseIBECacheEntry", fnctLine, (char *)0)
return (status);
}
int VoltSetIBECacheEntry (
Pointer ibeCacheCtx,
VoltMpIntCtx *mpCtx,
unsigned char *element,
unsigned int elementLen,
unsigned int *returnIndex
)
{
int status, status2;
int lockAcquired = 0;
unsigned int flag, primeLen, subprimeLen, refLen, accelCount, offset, index;
unsigned char *ref;
VoltIBECacheCtx *ctx = (VoltIBECacheCtx *)ibeCacheCtx;
VoltIBELocalCache *cache = (VoltIBELocalCache *)(ctx->localCtx);
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VoltIBECacheEntry *entry = (VoltIBECacheEntry *)0;
VoltIBECacheEntry *nextEntry;
bb1_context_t *bbCtx = (bb1_context_t *)0;
bf_context_t *bfCtx = (bf_context_t *)0;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Isolate the flag, prime, subprime, base point, and public point.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SET;
if (elementLen < 14)
break;
/* The first value is the flag.
*/
flag = GetIntegerBE (element, 2);
/* The next numbers are the primeLen, subprimeLen, and accelCount.
*/
primeLen = GetIntegerBE (element + 2, 4);
subprimeLen = GetIntegerBE (element + 6, 4);
accelCount = GetIntegerBE (element + 10, 4);
/* If BF, the total byte length should be
* 14 + subprimeLen + [(accelCount * 2) + 5] * primeLen
* If BB, the total length should be
* 14 + subprimeLen + [(accelCount * 6) + 9] * primeLen
* If neither, error.
*/
VOLT_SET_FNCT_LINE (fnctLine)
if (flag == VT_IBE_CACHE_ENTRY_BF_TYPE1)
offset = (accelCount * 2) + 5;
else if (flag == VT_IBE_CACHE_ENTRY_BB_TYPE1)
offset = (accelCount * 6) + 9;
else
break;
offset *= primeLen;
offset += subprimeLen + 14;
VOLT_SET_FNCT_LINE (fnctLine)
if (elementLen != offset)
break;
/* The reference is the block of coordinates after the subprime.
*/
ref = element + 14 + primeLen + subprimeLen;
refLen = 4 * primeLen;
/* Acquire the cache lock to syncronize access */
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = ctx->LockIBECache(ibeCacheCtx);
if (status != 0)
break;
lockAcquired = 1;
/* Run through the list, check to see if the entry is already in
* the cache. If not, we'll find the end of the list, where we'll
* add a new entry.
*/
status = 0;
nextEntry = cache->cacheList;
index = 0;
while (nextEntry != (VoltIBECacheEntry *)0)
{
entry = nextEntry;
if (entry->reference.len == refLen)
{
if (Z2Memcmp (ref, entry->reference.data, refLen) == 0)
break;
}
nextEntry = (VoltIBECacheEntry *)(entry->nextEntry);
index++;
}
*returnIndex = index;
/* If nextEntry is not NULL, we broke out early. If we broke out
* early, we found a match.
*/
if (nextEntry != (VoltIBECacheEntry *)0)
break;
/* Build a bfCtx or bbCtx.
*/
if (flag == VT_IBE_CACHE_ENTRY_BF_TYPE1)
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = BuildBfCtxFromCacheEntry (
libCtx, mpCtx, primeLen, subprimeLen, accelCount, element, &bfCtx);
}
else
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = BuildBbCtxFromCacheEntry (
libCtx, mpCtx, primeLen, subprimeLen, accelCount, element, &bbCtx);
}
} while (0);
if (lockAcquired)
{
status2 = ctx->UnlockIBECache(ibeCacheCtx);
if (status == 0)
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = status2;
}
}
/* We had to build the bfCtx or bbCtx to get it into the cache. But
* we don't really need it, so release it.
*/
VoltReleaseBfCtx (libCtx, &bfCtx);
VoltReleaseBbCtx (libCtx, &bbCtx);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, ibeCacheCtx, status, 0, errorType,
(char *)0, "VoltSetIBECacheEntry", fnctLine, (char *)0)
return (status);
}
int VoltDeleteIBECacheEntry (
Pointer ibeCacheCtx,
unsigned int index
)
{
int status, status2;
int lockAcquired = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -