static void mii_putbit(unsigned int ioaddr, unsigned data) { #if 1 if (data) { PutByte(XIRCREG2_GPR2, 0x0c|2|0); udelay(1); PutByte(XIRCREG2_GPR2, 0x0c|2|1); udelay(1); } else { PutByte(XIRCREG2_GPR2, 0x0c|0|0); udelay(1); PutByte(XIRCREG2_GPR2, 0x0c|0|1); udelay(1); } #else if (data) { PutWord(XIRCREG2_GPR2-1, 0x0e0e); udelay(1); PutWord(XIRCREG2_GPR2-1, 0x0f0f); udelay(1); } else { PutWord(XIRCREG2_GPR2-1, 0x0c0c); udelay(1); PutWord(XIRCREG2_GPR2-1, 0x0d0d); udelay(1); } #endif }
DecodingResult PSSR_MEM_Base::RecoverMessageFromRepresentative( HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, byte *representative, size_t representativeBitLength, byte *recoverableMessage) const { assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize())); const size_t u = hashIdentifier.second + 1; const size_t representativeByteLength = BitsToBytes(representativeBitLength); const size_t digestSize = hash.DigestSize(); const size_t saltSize = SaltLen(digestSize); const byte *const h = representative + representativeByteLength - u - digestSize; SecByteBlock digest(digestSize); hash.Final(digest); DecodingResult result(0); bool &valid = result.isValidCoding; size_t &recoverableMessageLength = result.messageLength; valid = (representative[representativeByteLength - 1] == (hashIdentifier.second ? 0xcc : 0xbc)) && valid; valid = VerifyBufsEqual(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second) && valid; GetMGF().GenerateAndMask(hash, representative, representativeByteLength - u - digestSize, h, digestSize); if (representativeBitLength % 8 != 0) representative[0] = (byte)Crop(representative[0], representativeBitLength % 8); // extract salt and recoverableMessage from DB = 00 ... || 01 || M || salt byte *salt = representative + representativeByteLength - u - digestSize - saltSize; byte *M = std::find_if(representative, salt-1, std::bind2nd(std::not_equal_to<byte>(), 0)); recoverableMessageLength = salt-M-1; if (*M == 0x01 && (size_t)(M - representative - (representativeBitLength % 8 != 0)) >= MinPadLen(digestSize) && recoverableMessageLength <= MaxRecoverableLength(representativeBitLength, hashIdentifier.second, digestSize)) { memcpy(recoverableMessage, M+1, recoverableMessageLength); } else { recoverableMessageLength = 0; valid = false; } // verify H = hash of M' byte c[8]; PutWord(false, BIG_ENDIAN_ORDER, c, (word32)SafeRightShift<29>(recoverableMessageLength)); PutWord(false, BIG_ENDIAN_ORDER, c+4, word32(recoverableMessageLength << 3)); hash.Update(c, 8); hash.Update(recoverableMessage, recoverableMessageLength); hash.Update(digest, digestSize); hash.Update(salt, saltSize); valid = hash.Verify(h) && valid; if (!AllowRecovery() && valid && recoverableMessageLength != 0) {throw NotImplemented("PSSR_MEM: message recovery disabled");} return result; }
void COMFFileBuilder::StartRecord(uint8 type) { // Start building new record this->Type = type; // Save type RecordStart = Index = GetDataSize(); // Remember start position PutByte(Type); // Put type into record PutWord(0); // Reserve space for size, put in later }
void COMFFileBuilder::PutNumeric(uint32 x) { // Put word or dword into buffer, depending on type being even or odd if (Type & 1) { PutDword(x); // Type is odd, put 32 bits } else { if (x > 0xffff) err.submit(2304);// Index out of range PutWord(uint16(x)); // Type is even, put 16 bits } }
void _UnWord (void) { // UNWORD int32 val; val=atol(FWORD); if (val!=0) { AT=(val); } else { ADEL; // pop unknown command (-1) printf("\n unknown word "); PutWord(); printf("\n"); } }
void PSSR_MEM_Base::ComputeMessageRepresentative(RandomNumberGenerator &rng, const byte *recoverableMessage, size_t recoverableMessageLength, HashTransformation &hash, HashIdentifier hashIdentifier, bool messageEmpty, byte *representative, size_t representativeBitLength) const { assert(representativeBitLength >= MinRepresentativeBitLength(hashIdentifier.second, hash.DigestSize())); const size_t u = hashIdentifier.second + 1; const size_t representativeByteLength = BitsToBytes(representativeBitLength); const size_t digestSize = hash.DigestSize(); const size_t saltSize = SaltLen(digestSize); byte *const h = representative + representativeByteLength - u - digestSize; SecByteBlock digest(digestSize), salt(saltSize); hash.Final(digest); rng.GenerateBlock(salt, saltSize); // compute H = hash of M' byte c[8]; PutWord(false, BIG_ENDIAN_ORDER, c, (word32)SafeRightShift<29>(recoverableMessageLength)); PutWord(false, BIG_ENDIAN_ORDER, c+4, word32(recoverableMessageLength << 3)); hash.Update(c, 8); hash.Update(recoverableMessage, recoverableMessageLength); hash.Update(digest, digestSize); hash.Update(salt, saltSize); hash.Final(h); // compute representative GetMGF().GenerateAndMask(hash, representative, representativeByteLength - u - digestSize, h, digestSize, false); byte *xorStart = representative + representativeByteLength - u - digestSize - salt.size() - recoverableMessageLength - 1; xorStart[0] ^= 1; xorbuf(xorStart + 1, recoverableMessage, recoverableMessageLength); xorbuf(xorStart + 1 + recoverableMessageLength, salt, salt.size()); memcpy(representative + representativeByteLength - u, hashIdentifier.first, hashIdentifier.second); representative[representativeByteLength - 1] = hashIdentifier.second ? 0xcc : 0xbc; if (representativeBitLength % 8 != 0) representative[0] = (byte)Crop(representative[0], representativeBitLength % 8); }
unsigned int BufferedTransformation::ChannelPutWord32(const std::string &channel, word32 value, ByteOrder order, bool blocking) { FixedSizeSecBlock<byte, 4> buf; PutWord(false, order, buf, value); return ChannelPut(channel, buf, 4, blocking); }
size_t BufferedTransformation::ChannelPutWord32(const std::string &channel, word32 value, ByteOrder order, bool blocking) { PutWord(false, order, m_buf, value); return ChannelPut(channel, m_buf, 4, blocking); }
static void AddOrDeleteGroup(int add, char *groupName, char *inGroupsFilePath, char *inTempGroupsFilePath) { char line[MAX_LINE_LEN]; char lineFromFile[MAX_LINE_LEN]; char groupNameFromFile[MAX_STRING_LEN + 1]; bool foundGroup = false; FILE *groupsFilePtr, *tempGroupsFilePtr; bool addedGroup = false; if (!(groupsFilePtr = fopen(inGroupsFilePath, "r"))) { if (add) { char buffer[kErrorStrSize]; qtss_fprintf(stderr, "Could not open groups file %s for reading. (err=%d:%s)\n", inGroupsFilePath, errno, qtss_strerror(errno, buffer, sizeof(buffer))); CleanupAndExit(); } else return; } if (!(tempGroupsFilePtr = fopen(inTempGroupsFilePath, "w"))) { char buffer[kErrorStrSize]; qtss_fprintf(stderr, "Could not open temp groups file. (err=%d %s)\n", errno, qtss_strerror(errno, buffer, sizeof(buffer))); CleanupAndExit(); } while (!(GetLine(line, MAX_LINE_LEN, groupsFilePtr))) { //write comments and blank lines out to temp file if (foundGroup || (line[0] == '#') || (line[0] == 0)) { PutLine(tempGroupsFilePtr, line); continue; } strcpy(lineFromFile, line); EatWhitespace(lineFromFile); GetWord(groupNameFromFile, lineFromFile, ':'); //if it's not the group we're looking for, write the line out to the temp file if ((groupName != NULL) && strcmp(groupName, groupNameFromFile) != 0) { PutLine(tempGroupsFilePtr, line); continue; } else if (add) // if we are trying to add the group and it already exists, leave it in { PutLine(tempGroupsFilePtr, line); addedGroup = true; } foundGroup = true; } if (add && !addedGroup) { PutWord(tempGroupsFilePtr, groupName, ':'); fputc('\n', tempGroupsFilePtr); } fclose(tempGroupsFilePtr); fclose(groupsFilePtr); // Rename the temp groups file to the groups file //remove(qtusersFilePath); if (rename(inTempGroupsFilePath, inGroupsFilePath) != 0) { perror("rename failed with error"); CleanupAndExit(); } }
void _PutWord (void) { // PUTWORD PutWord(); }
/*---------------------------------------------------------------------------- > Function Name: RtStatus_t ChangeToLowLevelDir(int32_t HandleNumber,FindData_t *_finddata,int32_t StartingCluster) FunctionType: Reentrant Inputs: 1) Handle Number 2) FindData_t Structure 3) Starting Cluster Outputs: Returns SUCCESS on success else an Error Code Description: Changes to low level directory if available within the given directory and updates the Handle < ----------------------------------------------------------------------------*/ RtStatus_t ChangeToLowLevelDir(int32_t HandleNumber, FindData_t * _finddata, int32_t StartingCluster) { RtStatus_t RetValue = SUCCESS; int32_t RecordNumber; uint8_t Buffer[32]; int32_t ClusterNumber = 0; uint8_t Buf[5]; // int64_t lTemp; PutWord(Buf, 0x2e2e, 0); if ((RetValue = Fseek(HandleNumber, -DIRRECORDSIZE, SEEK_CUR))) return RetValue; if ((RetValue = Isdirectoryempty(HandleNumber)) == SUCCESS) { if ((ReadDirectoryRecord(HandleNumber, 0, Buffer)) <= 0) return ERROR_OS_FILESYSTEM_NO_MATCHING_RECORD; // sdk2.6 changed this from right shift to a left shift. ClusterNumber = ((FSGetWord(Buffer, DIR_FSTCLUSLOOFFSET)) | (FSGetWord(Buffer, DIR_FSTCLUSHIOFFSET) << 16)); if ((RetValue = Fseek(HandleNumber, 0, SEEK_SET)) < 0) return RetValue; if ((RetValue = Chdir((uint8_t *) & Buf)) < 0) return RetValue; Handle[HandleNumber] = Handle[CWD_HANDLE]; if ((RecordNumber = DelGetRecordNumber(HandleNumber, ClusterNumber)) < 0) return ERROR_OS_FILESYSTEM_NO_MATCHING_RECORD; if ((RetValue = FileRemove(RecordNumber, HandleNumber)) < 0) return RetValue; if (Handle[HandleNumber].StartingCluster == MediaTable[Handle[HandleNumber].Device].RootdirCluster || Handle[HandleNumber].StartingCluster == StartingCluster) return ERROR_OS_FILESYSTEM_DIR_NOT_REMOVABLE; return SUCCESS; } if ((ReadDirectoryRecord(HandleNumber, (_finddata->startrecord - 1), Buffer)) <= 0) return ERROR_OS_FILESYSTEM_NO_MATCHING_RECORD; if ((RetValue = Fseek(HandleNumber, -DIRRECORDSIZE, SEEK_CUR))) return RetValue; // sdk2.6 changed this from a right shift to a left shift. ClusterNumber = ((FSGetWord(Buffer, DIR_FSTCLUSLOOFFSET)) | (FSGetWord(Buffer, DIR_FSTCLUSHIOFFSET) << 16)); UpdateHandle(HandleNumber, ClusterNumber); Handle[CWD_HANDLE] = Handle[HandleNumber]; return SUCCESS; }
/*---------------------------------------------------------------------------- > Function Name: RtStatus_t DeleteAllRecords(int32_t StartingCluster,FindData_t *_finddata) FunctionType: Reentrant Inputs: 1) StartingCluster 2) FindData_t structure Outputs: Returns an Error if function fails Description: Deletes all the files and directories of the specified path < ----------------------------------------------------------------------------*/ RtStatus_t DeleteAllRecords(int32_t StartingCluster, FindData_t * _finddata) { RtStatus_t RetValue = SUCCESS; int32_t HandleNumber = 0; uint8_t Buf[5]; int32_t TemphandleNumber = 0; ClearData(_finddata); PutWord(Buf, 0x2e2a, 0); Buf[2] = 0x2a; while (1) { TemphandleNumber = HandleNumber; if ((HandleNumber = FindFirst(_finddata, (uint8_t *) Buf)) < 0) { /* FindFirst function returns handle number with setting mode = READ + DIRECTORY so we have to set write mode for this handle */ HandleNumber = TemphandleNumber; Handle[HandleNumber].HandleActive = 1; Handle[HandleNumber].Mode = (FileSystemModeTypes_t) (Handle[HandleNumber].Mode | WRITE_MODE); if ((RetValue = ChangeToLowLevelDir(HandleNumber, _finddata, StartingCluster)) < 0) { Freehandle(HandleNumber); return RetValue; } ClearData(_finddata); Freehandle(HandleNumber); continue; } Handle[HandleNumber].Mode = (FileSystemModeTypes_t) (Handle[HandleNumber].Mode | WRITE_MODE); if ((_finddata->attrib & DIRECTORY) == DIRECTORY) { if ((RetValue = ChangeToLowLevelDir(HandleNumber, _finddata, StartingCluster)) < 0) { Freehandle(HandleNumber); return RetValue; } ClearData(_finddata); Freehandle(HandleNumber); continue; } else { if ((RetValue = FileRemove(_finddata->startrecord - 1, HandleNumber)) < 0) { Freehandle(HandleNumber); return RetValue; } } while (1) { if ((RetValue = FindNext(HandleNumber, _finddata)) < 0) { if ((RetValue = ChangeToLowLevelDir(HandleNumber, _finddata, StartingCluster)) < 0) { Freehandle(HandleNumber); return RetValue; } ClearData(_finddata); Freehandle(HandleNumber); break; } if ((_finddata->attrib & DIRECTORY) == DIRECTORY) { if ((RetValue = ChangeToLowLevelDir(HandleNumber, _finddata, StartingCluster)) < 0) { Freehandle(HandleNumber); return RetValue; } ClearData(_finddata); Freehandle(HandleNumber); break; } else { if ((RetValue = FileRemove(_finddata->startrecord - 1, HandleNumber)) < 0) { Freehandle(HandleNumber); return RetValue; } } } } // while(1) }